1 /*****************************************************************************/
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial.h>
36 #include <linux/cd1400.h>
37 #include <linux/sc26198.h>
38 #include <linux/comstats.h>
39 #include <linux/stallion.h>
40 #include <linux/ioport.h>
41 #include <linux/init.h>
42 #include <linux/smp_lock.h>
43 #include <linux/devfs_fs_kernel.h>
44 #include <linux/device.h>
45 #include <linux/delay.h>
48 #include <asm/uaccess.h>
51 #include <linux/pci.h>
54 /*****************************************************************************/
57 * Define different board types. Use the standard Stallion "assigned"
58 * board numbers. Boards supported in this driver are abbreviated as
59 * EIO = EasyIO and ECH = EasyConnection 8/32.
65 #define BRD_ECH64PCI 27
66 #define BRD_EASYIOPCI 28
69 * Define a configuration structure to hold the board configuration.
70 * Need to set this up in the code (for now) with the boards that are
71 * to be configured into the system. This is what needs to be modified
72 * when adding/removing/modifying boards. Each line entry in the
73 * stl_brdconf[] array is a board. Each line contains io/irq/memory
74 * ranges for that board (as well as what type of board it is).
76 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
77 * This line would configure an EasyIO board (4 or 8, no difference),
78 * at io address 2a0 and irq 10.
80 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
81 * This line will configure an EasyConnection 8/32 board at primary io
82 * address 2a8, secondary io address 280 and irq 12.
83 * Enter as many lines into this array as you want (only the first 4
84 * will actually be used!). Any combination of EasyIO and EasyConnection
85 * boards can be specified. EasyConnection 8/32 boards can share their
86 * secondary io addresses between each other.
88 * NOTE: there is no need to put any entries in this table for PCI
89 * boards. They will be found automatically by the driver - provided
90 * PCI BIOS32 support is compiled into the kernel.
97 unsigned long memaddr
;
102 static stlconf_t stl_brdconf
[] = {
103 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
106 static int stl_nrbrds
= ARRAY_SIZE(stl_brdconf
);
108 /*****************************************************************************/
111 * Define some important driver characteristics. Device major numbers
112 * allocated as per Linux Device Registry.
114 #ifndef STL_SIOMEMMAJOR
115 #define STL_SIOMEMMAJOR 28
117 #ifndef STL_SERIALMAJOR
118 #define STL_SERIALMAJOR 24
120 #ifndef STL_CALLOUTMAJOR
121 #define STL_CALLOUTMAJOR 25
125 * Set the TX buffer size. Bigger is better, but we don't want
126 * to chew too much memory with buffers!
128 #define STL_TXBUFLOW 512
129 #define STL_TXBUFSIZE 4096
131 /*****************************************************************************/
134 * Define our local driver identity first. Set up stuff to deal with
135 * all the local structures required by a serial tty driver.
137 static char *stl_drvtitle
= "Stallion Multiport Serial Driver";
138 static char *stl_drvname
= "stallion";
139 static char *stl_drvversion
= "5.6.0";
141 static struct tty_driver
*stl_serial
;
144 * We will need to allocate a temporary write buffer for chars that
145 * come direct from user space. The problem is that a copy from user
146 * space might cause a page fault (typically on a system that is
147 * swapping!). All ports will share one buffer - since if the system
148 * is already swapping a shared buffer won't make things any worse.
150 static char *stl_tmpwritebuf
;
151 static DECLARE_MUTEX(stl_tmpwritesem
);
154 * Define a local default termios struct. All ports will be created
155 * with this termios initially. Basically all it defines is a raw port
156 * at 9600, 8 data bits, 1 stop bit.
158 static struct termios stl_deftermios
= {
159 .c_cflag
= (B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
),
164 * Define global stats structures. Not used often, and can be
165 * re-used for each stats call.
167 static comstats_t stl_comstats
;
168 static combrd_t stl_brdstats
;
169 static stlbrd_t stl_dummybrd
;
170 static stlport_t stl_dummyport
;
173 * Define global place to put buffer overflow characters.
175 static char stl_unwanted
[SC26198_RXFIFOSIZE
];
177 /*****************************************************************************/
179 static stlbrd_t
*stl_brds
[STL_MAXBRDS
];
182 * Per board state flags. Used with the state field of the board struct.
183 * Not really much here!
185 #define BRD_FOUND 0x1
188 * Define the port structure istate flags. These set of flags are
189 * modified at interrupt time - so setting and reseting them needs
190 * to be atomic. Use the bit clear/setting routines for this.
192 #define ASYI_TXBUSY 1
194 #define ASYI_DCDCHANGE 3
195 #define ASYI_TXFLOWED 4
198 * Define an array of board names as printable strings. Handy for
199 * referencing boards when printing trace and stuff.
201 static char *stl_brdnames
[] = {
233 /*****************************************************************************/
236 * Define some string labels for arguments passed from the module
237 * load line. These allow for easy board definitions, and easy
238 * modification of the io, memory and irq resoucres.
240 static int stl_nargs
= 0;
241 static char *board0
[4];
242 static char *board1
[4];
243 static char *board2
[4];
244 static char *board3
[4];
246 static char **stl_brdsp
[] = {
254 * Define a set of common board names, and types. This is used to
255 * parse any module arguments.
258 typedef struct stlbrdtype
{
263 static stlbrdtype_t stl_brdstr
[] = {
264 { "easyio", BRD_EASYIO
},
265 { "eio", BRD_EASYIO
},
266 { "20", BRD_EASYIO
},
267 { "ec8/32", BRD_ECH
},
268 { "ec8/32-at", BRD_ECH
},
269 { "ec8/32-isa", BRD_ECH
},
271 { "echat", BRD_ECH
},
273 { "ec8/32-mc", BRD_ECHMC
},
274 { "ec8/32-mca", BRD_ECHMC
},
275 { "echmc", BRD_ECHMC
},
276 { "echmca", BRD_ECHMC
},
278 { "ec8/32-pc", BRD_ECHPCI
},
279 { "ec8/32-pci", BRD_ECHPCI
},
280 { "26", BRD_ECHPCI
},
281 { "ec8/64-pc", BRD_ECH64PCI
},
282 { "ec8/64-pci", BRD_ECH64PCI
},
283 { "ech-pci", BRD_ECH64PCI
},
284 { "echpci", BRD_ECH64PCI
},
285 { "echpc", BRD_ECH64PCI
},
286 { "27", BRD_ECH64PCI
},
287 { "easyio-pc", BRD_EASYIOPCI
},
288 { "easyio-pci", BRD_EASYIOPCI
},
289 { "eio-pci", BRD_EASYIOPCI
},
290 { "eiopci", BRD_EASYIOPCI
},
291 { "28", BRD_EASYIOPCI
},
295 * Define the module agruments.
297 MODULE_AUTHOR("Greg Ungerer");
298 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
299 MODULE_LICENSE("GPL");
301 module_param_array(board0
, charp
, &stl_nargs
, 0);
302 MODULE_PARM_DESC(board0
, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
303 module_param_array(board1
, charp
, &stl_nargs
, 0);
304 MODULE_PARM_DESC(board1
, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
305 module_param_array(board2
, charp
, &stl_nargs
, 0);
306 MODULE_PARM_DESC(board2
, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
307 module_param_array(board3
, charp
, &stl_nargs
, 0);
308 MODULE_PARM_DESC(board3
, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
310 /*****************************************************************************/
313 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
314 * to the directly accessible io ports of these boards (not the uarts -
315 * they are in cd1400.h and sc26198.h).
317 #define EIO_8PORTRS 0x04
318 #define EIO_4PORTRS 0x05
319 #define EIO_8PORTDI 0x00
320 #define EIO_8PORTM 0x06
322 #define EIO_IDBITMASK 0x07
324 #define EIO_BRDMASK 0xf0
327 #define ID_BRD16 0x30
329 #define EIO_INTRPEND 0x08
330 #define EIO_INTEDGE 0x00
331 #define EIO_INTLEVEL 0x08
335 #define ECH_IDBITMASK 0xe0
336 #define ECH_BRDENABLE 0x08
337 #define ECH_BRDDISABLE 0x00
338 #define ECH_INTENABLE 0x01
339 #define ECH_INTDISABLE 0x00
340 #define ECH_INTLEVEL 0x02
341 #define ECH_INTEDGE 0x00
342 #define ECH_INTRPEND 0x01
343 #define ECH_BRDRESET 0x01
345 #define ECHMC_INTENABLE 0x01
346 #define ECHMC_BRDRESET 0x02
348 #define ECH_PNLSTATUS 2
349 #define ECH_PNL16PORT 0x20
350 #define ECH_PNLIDMASK 0x07
351 #define ECH_PNLXPID 0x40
352 #define ECH_PNLINTRPEND 0x80
354 #define ECH_ADDR2MASK 0x1e0
357 * Define the vector mapping bits for the programmable interrupt board
358 * hardware. These bits encode the interrupt for the board to use - it
359 * is software selectable (except the EIO-8M).
361 static unsigned char stl_vecmap
[] = {
362 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
363 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
367 * Set up enable and disable macros for the ECH boards. They require
368 * the secondary io address space to be activated and deactivated.
369 * This way all ECH boards can share their secondary io region.
370 * If this is an ECH-PCI board then also need to set the page pointer
371 * to point to the correct page.
373 #define BRDENABLE(brdnr,pagenr) \
374 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
375 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
376 stl_brds[(brdnr)]->ioctrl); \
377 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
378 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
380 #define BRDDISABLE(brdnr) \
381 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
382 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
383 stl_brds[(brdnr)]->ioctrl);
385 #define STL_CD1400MAXBAUD 230400
386 #define STL_SC26198MAXBAUD 460800
388 #define STL_BAUDBASE 115200
389 #define STL_CLOSEDELAY (5 * HZ / 10)
391 /*****************************************************************************/
396 * Define the Stallion PCI vendor and device IDs.
398 #ifndef PCI_VENDOR_ID_STALLION
399 #define PCI_VENDOR_ID_STALLION 0x124d
401 #ifndef PCI_DEVICE_ID_ECHPCI832
402 #define PCI_DEVICE_ID_ECHPCI832 0x0000
404 #ifndef PCI_DEVICE_ID_ECHPCI864
405 #define PCI_DEVICE_ID_ECHPCI864 0x0002
407 #ifndef PCI_DEVICE_ID_EIOPCI
408 #define PCI_DEVICE_ID_EIOPCI 0x0003
412 * Define structure to hold all Stallion PCI boards.
414 typedef struct stlpcibrd
{
415 unsigned short vendid
;
416 unsigned short devid
;
420 static stlpcibrd_t stl_pcibrds
[] = {
421 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI864
, BRD_ECH64PCI
},
422 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_EIOPCI
, BRD_EASYIOPCI
},
423 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI832
, BRD_ECHPCI
},
424 { PCI_VENDOR_ID_NS
, PCI_DEVICE_ID_NS_87410
, BRD_ECHPCI
},
427 static int stl_nrpcibrds
= ARRAY_SIZE(stl_pcibrds
);
431 /*****************************************************************************/
434 * Define macros to extract a brd/port number from a minor number.
436 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
437 #define MINOR2PORT(min) ((min) & 0x3f)
440 * Define a baud rate table that converts termios baud rate selector
441 * into the actual baud rate value. All baud rate calculations are
442 * based on the actual baud rate required.
444 static unsigned int stl_baudrates
[] = {
445 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
446 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
450 * Define some handy local macros...
453 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
456 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
458 /*****************************************************************************/
461 * Declare all those functions in this driver!
464 static void stl_argbrds(void);
465 static int stl_parsebrd(stlconf_t
*confp
, char **argp
);
467 static unsigned long stl_atol(char *str
);
469 static int stl_init(void);
470 static int stl_open(struct tty_struct
*tty
, struct file
*filp
);
471 static void stl_close(struct tty_struct
*tty
, struct file
*filp
);
472 static int stl_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
);
473 static void stl_putchar(struct tty_struct
*tty
, unsigned char ch
);
474 static void stl_flushchars(struct tty_struct
*tty
);
475 static int stl_writeroom(struct tty_struct
*tty
);
476 static int stl_charsinbuffer(struct tty_struct
*tty
);
477 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
);
478 static void stl_settermios(struct tty_struct
*tty
, struct termios
*old
);
479 static void stl_throttle(struct tty_struct
*tty
);
480 static void stl_unthrottle(struct tty_struct
*tty
);
481 static void stl_stop(struct tty_struct
*tty
);
482 static void stl_start(struct tty_struct
*tty
);
483 static void stl_flushbuffer(struct tty_struct
*tty
);
484 static void stl_breakctl(struct tty_struct
*tty
, int state
);
485 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
);
486 static void stl_sendxchar(struct tty_struct
*tty
, char ch
);
487 static void stl_hangup(struct tty_struct
*tty
);
488 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
);
489 static int stl_portinfo(stlport_t
*portp
, int portnr
, char *pos
);
490 static int stl_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
);
492 static int stl_brdinit(stlbrd_t
*brdp
);
493 static int stl_initports(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
494 static int stl_getserial(stlport_t
*portp
, struct serial_struct __user
*sp
);
495 static int stl_setserial(stlport_t
*portp
, struct serial_struct __user
*sp
);
496 static int stl_getbrdstats(combrd_t __user
*bp
);
497 static int stl_getportstats(stlport_t
*portp
, comstats_t __user
*cp
);
498 static int stl_clrportstats(stlport_t
*portp
, comstats_t __user
*cp
);
499 static int stl_getportstruct(stlport_t __user
*arg
);
500 static int stl_getbrdstruct(stlbrd_t __user
*arg
);
501 static int stl_waitcarrier(stlport_t
*portp
, struct file
*filp
);
502 static int stl_eiointr(stlbrd_t
*brdp
);
503 static int stl_echatintr(stlbrd_t
*brdp
);
504 static int stl_echmcaintr(stlbrd_t
*brdp
);
505 static int stl_echpciintr(stlbrd_t
*brdp
);
506 static int stl_echpci64intr(stlbrd_t
*brdp
);
507 static void stl_offintr(void *private);
508 static void *stl_memalloc(int len
);
509 static stlbrd_t
*stl_allocbrd(void);
510 static stlport_t
*stl_getport(int brdnr
, int panelnr
, int portnr
);
512 static inline int stl_initbrds(void);
513 static inline int stl_initeio(stlbrd_t
*brdp
);
514 static inline int stl_initech(stlbrd_t
*brdp
);
515 static inline int stl_getbrdnr(void);
518 static inline int stl_findpcibrds(void);
519 static inline int stl_initpcibrd(int brdtype
, struct pci_dev
*devp
);
523 * CD1400 uart specific handling functions.
525 static void stl_cd1400setreg(stlport_t
*portp
, int regnr
, int value
);
526 static int stl_cd1400getreg(stlport_t
*portp
, int regnr
);
527 static int stl_cd1400updatereg(stlport_t
*portp
, int regnr
, int value
);
528 static int stl_cd1400panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
529 static void stl_cd1400portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
530 static void stl_cd1400setport(stlport_t
*portp
, struct termios
*tiosp
);
531 static int stl_cd1400getsignals(stlport_t
*portp
);
532 static void stl_cd1400setsignals(stlport_t
*portp
, int dtr
, int rts
);
533 static void stl_cd1400ccrwait(stlport_t
*portp
);
534 static void stl_cd1400enablerxtx(stlport_t
*portp
, int rx
, int tx
);
535 static void stl_cd1400startrxtx(stlport_t
*portp
, int rx
, int tx
);
536 static void stl_cd1400disableintrs(stlport_t
*portp
);
537 static void stl_cd1400sendbreak(stlport_t
*portp
, int len
);
538 static void stl_cd1400flowctrl(stlport_t
*portp
, int state
);
539 static void stl_cd1400sendflow(stlport_t
*portp
, int state
);
540 static void stl_cd1400flush(stlport_t
*portp
);
541 static int stl_cd1400datastate(stlport_t
*portp
);
542 static void stl_cd1400eiointr(stlpanel_t
*panelp
, unsigned int iobase
);
543 static void stl_cd1400echintr(stlpanel_t
*panelp
, unsigned int iobase
);
544 static void stl_cd1400txisr(stlpanel_t
*panelp
, int ioaddr
);
545 static void stl_cd1400rxisr(stlpanel_t
*panelp
, int ioaddr
);
546 static void stl_cd1400mdmisr(stlpanel_t
*panelp
, int ioaddr
);
548 static inline int stl_cd1400breakisr(stlport_t
*portp
, int ioaddr
);
551 * SC26198 uart specific handling functions.
553 static void stl_sc26198setreg(stlport_t
*portp
, int regnr
, int value
);
554 static int stl_sc26198getreg(stlport_t
*portp
, int regnr
);
555 static int stl_sc26198updatereg(stlport_t
*portp
, int regnr
, int value
);
556 static int stl_sc26198getglobreg(stlport_t
*portp
, int regnr
);
557 static int stl_sc26198panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
558 static void stl_sc26198portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
559 static void stl_sc26198setport(stlport_t
*portp
, struct termios
*tiosp
);
560 static int stl_sc26198getsignals(stlport_t
*portp
);
561 static void stl_sc26198setsignals(stlport_t
*portp
, int dtr
, int rts
);
562 static void stl_sc26198enablerxtx(stlport_t
*portp
, int rx
, int tx
);
563 static void stl_sc26198startrxtx(stlport_t
*portp
, int rx
, int tx
);
564 static void stl_sc26198disableintrs(stlport_t
*portp
);
565 static void stl_sc26198sendbreak(stlport_t
*portp
, int len
);
566 static void stl_sc26198flowctrl(stlport_t
*portp
, int state
);
567 static void stl_sc26198sendflow(stlport_t
*portp
, int state
);
568 static void stl_sc26198flush(stlport_t
*portp
);
569 static int stl_sc26198datastate(stlport_t
*portp
);
570 static void stl_sc26198wait(stlport_t
*portp
);
571 static void stl_sc26198txunflow(stlport_t
*portp
, struct tty_struct
*tty
);
572 static void stl_sc26198intr(stlpanel_t
*panelp
, unsigned int iobase
);
573 static void stl_sc26198txisr(stlport_t
*port
);
574 static void stl_sc26198rxisr(stlport_t
*port
, unsigned int iack
);
575 static void stl_sc26198rxbadch(stlport_t
*portp
, unsigned char status
, char ch
);
576 static void stl_sc26198rxbadchars(stlport_t
*portp
);
577 static void stl_sc26198otherisr(stlport_t
*port
, unsigned int iack
);
579 /*****************************************************************************/
582 * Generic UART support structure.
584 typedef struct uart
{
585 int (*panelinit
)(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
586 void (*portinit
)(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
587 void (*setport
)(stlport_t
*portp
, struct termios
*tiosp
);
588 int (*getsignals
)(stlport_t
*portp
);
589 void (*setsignals
)(stlport_t
*portp
, int dtr
, int rts
);
590 void (*enablerxtx
)(stlport_t
*portp
, int rx
, int tx
);
591 void (*startrxtx
)(stlport_t
*portp
, int rx
, int tx
);
592 void (*disableintrs
)(stlport_t
*portp
);
593 void (*sendbreak
)(stlport_t
*portp
, int len
);
594 void (*flowctrl
)(stlport_t
*portp
, int state
);
595 void (*sendflow
)(stlport_t
*portp
, int state
);
596 void (*flush
)(stlport_t
*portp
);
597 int (*datastate
)(stlport_t
*portp
);
598 void (*intr
)(stlpanel_t
*panelp
, unsigned int iobase
);
602 * Define some macros to make calling these functions nice and clean.
604 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
605 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
606 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
607 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
608 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
609 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
610 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
611 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
612 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
613 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
614 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
615 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
616 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
618 /*****************************************************************************/
621 * CD1400 UART specific data initialization.
623 static uart_t stl_cd1400uart
= {
627 stl_cd1400getsignals
,
628 stl_cd1400setsignals
,
629 stl_cd1400enablerxtx
,
631 stl_cd1400disableintrs
,
641 * Define the offsets within the register bank of a cd1400 based panel.
642 * These io address offsets are common to the EasyIO board as well.
650 #define EREG_BANKSIZE 8
652 #define CD1400_CLK 25000000
653 #define CD1400_CLK8M 20000000
656 * Define the cd1400 baud rate clocks. These are used when calculating
657 * what clock and divisor to use for the required baud rate. Also
658 * define the maximum baud rate allowed, and the default base baud.
660 static int stl_cd1400clkdivs
[] = {
661 CD1400_CLK0
, CD1400_CLK1
, CD1400_CLK2
, CD1400_CLK3
, CD1400_CLK4
664 /*****************************************************************************/
667 * SC26198 UART specific data initization.
669 static uart_t stl_sc26198uart
= {
670 stl_sc26198panelinit
,
673 stl_sc26198getsignals
,
674 stl_sc26198setsignals
,
675 stl_sc26198enablerxtx
,
676 stl_sc26198startrxtx
,
677 stl_sc26198disableintrs
,
678 stl_sc26198sendbreak
,
682 stl_sc26198datastate
,
687 * Define the offsets within the register bank of a sc26198 based panel.
695 #define XP_BANKSIZE 4
698 * Define the sc26198 baud rate table. Offsets within the table
699 * represent the actual baud rate selector of sc26198 registers.
701 static unsigned int sc26198_baudtable
[] = {
702 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
703 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
704 230400, 460800, 921600
707 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
709 /*****************************************************************************/
712 * Define the driver info for a user level control device. Used mainly
713 * to get at port stats - only not using the port device itself.
715 static struct file_operations stl_fsiomem
= {
716 .owner
= THIS_MODULE
,
717 .ioctl
= stl_memioctl
,
720 /*****************************************************************************/
722 static struct class *stallion_class
;
725 * Loadable module initialization stuff.
728 static int __init
stallion_module_init(void)
733 printk("init_module()\n");
739 restore_flags(flags
);
744 /*****************************************************************************/
746 static void __exit
stallion_module_exit(void)
755 printk("cleanup_module()\n");
758 printk(KERN_INFO
"Unloading %s: version %s\n", stl_drvtitle
,
765 * Free up all allocated resources used by the ports. This includes
766 * memory and interrupts. As part of this process we will also do
767 * a hangup on every open port - to try to flush out any processes
768 * hanging onto ports.
770 i
= tty_unregister_driver(stl_serial
);
771 put_tty_driver(stl_serial
);
773 printk("STALLION: failed to un-register tty driver, "
775 restore_flags(flags
);
778 for (i
= 0; i
< 4; i
++) {
779 devfs_remove("staliomem/%d", i
);
780 class_device_destroy(stallion_class
, MKDEV(STL_SIOMEMMAJOR
, i
));
782 devfs_remove("staliomem");
783 if ((i
= unregister_chrdev(STL_SIOMEMMAJOR
, "staliomem")))
784 printk("STALLION: failed to un-register serial memory device, "
786 class_destroy(stallion_class
);
788 kfree(stl_tmpwritebuf
);
790 for (i
= 0; (i
< stl_nrbrds
); i
++) {
791 if ((brdp
= stl_brds
[i
]) == (stlbrd_t
*) NULL
)
794 free_irq(brdp
->irq
, brdp
);
796 for (j
= 0; (j
< STL_MAXPANELS
); j
++) {
797 panelp
= brdp
->panels
[j
];
798 if (panelp
== (stlpanel_t
*) NULL
)
800 for (k
= 0; (k
< STL_PORTSPERPANEL
); k
++) {
801 portp
= panelp
->ports
[k
];
802 if (portp
== (stlport_t
*) NULL
)
804 if (portp
->tty
!= (struct tty_struct
*) NULL
)
805 stl_hangup(portp
->tty
);
806 kfree(portp
->tx
.buf
);
812 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
813 if (brdp
->iosize2
> 0)
814 release_region(brdp
->ioaddr2
, brdp
->iosize2
);
817 stl_brds
[i
] = (stlbrd_t
*) NULL
;
820 restore_flags(flags
);
823 module_init(stallion_module_init
);
824 module_exit(stallion_module_exit
);
826 /*****************************************************************************/
829 * Check for any arguments passed in on the module load command line.
832 static void stl_argbrds(void)
839 printk("stl_argbrds()\n");
842 for (i
= stl_nrbrds
; (i
< stl_nargs
); i
++) {
843 memset(&conf
, 0, sizeof(conf
));
844 if (stl_parsebrd(&conf
, stl_brdsp
[i
]) == 0)
846 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
850 brdp
->brdtype
= conf
.brdtype
;
851 brdp
->ioaddr1
= conf
.ioaddr1
;
852 brdp
->ioaddr2
= conf
.ioaddr2
;
853 brdp
->irq
= conf
.irq
;
854 brdp
->irqtype
= conf
.irqtype
;
859 /*****************************************************************************/
862 * Convert an ascii string number into an unsigned long.
865 static unsigned long stl_atol(char *str
)
873 if ((*sp
== '0') && (*(sp
+1) == 'x')) {
876 } else if (*sp
== '0') {
883 for (; (*sp
!= 0); sp
++) {
884 c
= (*sp
> '9') ? (TOLOWER(*sp
) - 'a' + 10) : (*sp
- '0');
885 if ((c
< 0) || (c
>= base
)) {
886 printk("STALLION: invalid argument %s\n", str
);
890 val
= (val
* base
) + c
;
895 /*****************************************************************************/
898 * Parse the supplied argument string, into the board conf struct.
901 static int stl_parsebrd(stlconf_t
*confp
, char **argp
)
907 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp
, (int) argp
);
910 if ((argp
[0] == (char *) NULL
) || (*argp
[0] == 0))
913 for (sp
= argp
[0], i
= 0; ((*sp
!= 0) && (i
< 25)); sp
++, i
++)
916 for (i
= 0; i
< ARRAY_SIZE(stl_brdstr
); i
++) {
917 if (strcmp(stl_brdstr
[i
].name
, argp
[0]) == 0)
920 if (i
== ARRAY_SIZE(stl_brdstr
)) {
921 printk("STALLION: unknown board name, %s?\n", argp
[0]);
925 confp
->brdtype
= stl_brdstr
[i
].type
;
928 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
929 confp
->ioaddr1
= stl_atol(argp
[i
]);
931 if (confp
->brdtype
== BRD_ECH
) {
932 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
933 confp
->ioaddr2
= stl_atol(argp
[i
]);
936 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
937 confp
->irq
= stl_atol(argp
[i
]);
941 /*****************************************************************************/
944 * Local driver kernel memory allocation routine.
947 static void *stl_memalloc(int len
)
949 return (void *) kmalloc(len
, GFP_KERNEL
);
952 /*****************************************************************************/
955 * Allocate a new board structure. Fill out the basic info in it.
958 static stlbrd_t
*stl_allocbrd(void)
962 brdp
= (stlbrd_t
*) stl_memalloc(sizeof(stlbrd_t
));
963 if (brdp
== (stlbrd_t
*) NULL
) {
964 printk("STALLION: failed to allocate memory (size=%d)\n",
966 return (stlbrd_t
*) NULL
;
969 memset(brdp
, 0, sizeof(stlbrd_t
));
970 brdp
->magic
= STL_BOARDMAGIC
;
974 /*****************************************************************************/
976 static int stl_open(struct tty_struct
*tty
, struct file
*filp
)
980 unsigned int minordev
;
981 int brdnr
, panelnr
, portnr
, rc
;
984 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty
,
985 (int) filp
, tty
->name
);
988 minordev
= tty
->index
;
989 brdnr
= MINOR2BRD(minordev
);
990 if (brdnr
>= stl_nrbrds
)
992 brdp
= stl_brds
[brdnr
];
993 if (brdp
== (stlbrd_t
*) NULL
)
995 minordev
= MINOR2PORT(minordev
);
996 for (portnr
= -1, panelnr
= 0; (panelnr
< STL_MAXPANELS
); panelnr
++) {
997 if (brdp
->panels
[panelnr
] == (stlpanel_t
*) NULL
)
999 if (minordev
< brdp
->panels
[panelnr
]->nrports
) {
1003 minordev
-= brdp
->panels
[panelnr
]->nrports
;
1008 portp
= brdp
->panels
[panelnr
]->ports
[portnr
];
1009 if (portp
== (stlport_t
*) NULL
)
1013 * On the first open of the device setup the port hardware, and
1014 * initialize the per port data structure.
1017 tty
->driver_data
= portp
;
1020 if ((portp
->flags
& ASYNC_INITIALIZED
) == 0) {
1021 if (portp
->tx
.buf
== (char *) NULL
) {
1022 portp
->tx
.buf
= (char *) stl_memalloc(STL_TXBUFSIZE
);
1023 if (portp
->tx
.buf
== (char *) NULL
)
1025 portp
->tx
.head
= portp
->tx
.buf
;
1026 portp
->tx
.tail
= portp
->tx
.buf
;
1028 stl_setport(portp
, tty
->termios
);
1029 portp
->sigs
= stl_getsignals(portp
);
1030 stl_setsignals(portp
, 1, 1);
1031 stl_enablerxtx(portp
, 1, 1);
1032 stl_startrxtx(portp
, 1, 0);
1033 clear_bit(TTY_IO_ERROR
, &tty
->flags
);
1034 portp
->flags
|= ASYNC_INITIALIZED
;
1038 * Check if this port is in the middle of closing. If so then wait
1039 * until it is closed then return error status, based on flag settings.
1040 * The sleep here does not need interrupt protection since the wakeup
1041 * for it is done with the same context.
1043 if (portp
->flags
& ASYNC_CLOSING
) {
1044 interruptible_sleep_on(&portp
->close_wait
);
1045 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1047 return -ERESTARTSYS
;
1051 * Based on type of open being done check if it can overlap with any
1052 * previous opens still in effect. If we are a normal serial device
1053 * then also we might have to wait for carrier.
1055 if (!(filp
->f_flags
& O_NONBLOCK
)) {
1056 if ((rc
= stl_waitcarrier(portp
, filp
)) != 0)
1059 portp
->flags
|= ASYNC_NORMAL_ACTIVE
;
1064 /*****************************************************************************/
1067 * Possibly need to wait for carrier (DCD signal) to come high. Say
1068 * maybe because if we are clocal then we don't need to wait...
1071 static int stl_waitcarrier(stlport_t
*portp
, struct file
*filp
)
1073 unsigned long flags
;
1077 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp
, (int) filp
);
1083 if (portp
->tty
->termios
->c_cflag
& CLOCAL
)
1088 portp
->openwaitcnt
++;
1089 if (! tty_hung_up_p(filp
))
1093 stl_setsignals(portp
, 1, 1);
1094 if (tty_hung_up_p(filp
) ||
1095 ((portp
->flags
& ASYNC_INITIALIZED
) == 0)) {
1096 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1102 if (((portp
->flags
& ASYNC_CLOSING
) == 0) &&
1103 (doclocal
|| (portp
->sigs
& TIOCM_CD
))) {
1106 if (signal_pending(current
)) {
1110 interruptible_sleep_on(&portp
->open_wait
);
1113 if (! tty_hung_up_p(filp
))
1115 portp
->openwaitcnt
--;
1116 restore_flags(flags
);
1121 /*****************************************************************************/
1123 static void stl_close(struct tty_struct
*tty
, struct file
*filp
)
1126 unsigned long flags
;
1129 printk("stl_close(tty=%x,filp=%x)\n", (int) tty
, (int) filp
);
1132 portp
= tty
->driver_data
;
1133 if (portp
== (stlport_t
*) NULL
)
1138 if (tty_hung_up_p(filp
)) {
1139 restore_flags(flags
);
1142 if ((tty
->count
== 1) && (portp
->refcount
!= 1))
1143 portp
->refcount
= 1;
1144 if (portp
->refcount
-- > 1) {
1145 restore_flags(flags
);
1149 portp
->refcount
= 0;
1150 portp
->flags
|= ASYNC_CLOSING
;
1153 * May want to wait for any data to drain before closing. The BUSY
1154 * flag keeps track of whether we are still sending or not - it is
1155 * very accurate for the cd1400, not quite so for the sc26198.
1156 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1159 if (portp
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1160 tty_wait_until_sent(tty
, portp
->closing_wait
);
1161 stl_waituntilsent(tty
, (HZ
/ 2));
1163 portp
->flags
&= ~ASYNC_INITIALIZED
;
1164 stl_disableintrs(portp
);
1165 if (tty
->termios
->c_cflag
& HUPCL
)
1166 stl_setsignals(portp
, 0, 0);
1167 stl_enablerxtx(portp
, 0, 0);
1168 stl_flushbuffer(tty
);
1170 if (portp
->tx
.buf
!= (char *) NULL
) {
1171 kfree(portp
->tx
.buf
);
1172 portp
->tx
.buf
= (char *) NULL
;
1173 portp
->tx
.head
= (char *) NULL
;
1174 portp
->tx
.tail
= (char *) NULL
;
1176 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1177 tty_ldisc_flush(tty
);
1180 portp
->tty
= (struct tty_struct
*) NULL
;
1182 if (portp
->openwaitcnt
) {
1183 if (portp
->close_delay
)
1184 msleep_interruptible(jiffies_to_msecs(portp
->close_delay
));
1185 wake_up_interruptible(&portp
->open_wait
);
1188 portp
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1189 wake_up_interruptible(&portp
->close_wait
);
1190 restore_flags(flags
);
1193 /*****************************************************************************/
1196 * Write routine. Take data and stuff it in to the TX ring queue.
1197 * If transmit interrupts are not running then start them.
1200 static int stl_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
1203 unsigned int len
, stlen
;
1204 unsigned char *chbuf
;
1208 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1209 (int) tty
, (int) buf
, count
);
1212 if ((tty
== (struct tty_struct
*) NULL
) ||
1213 (stl_tmpwritebuf
== (char *) NULL
))
1215 portp
= tty
->driver_data
;
1216 if (portp
== (stlport_t
*) NULL
)
1218 if (portp
->tx
.buf
== (char *) NULL
)
1222 * If copying direct from user space we must cater for page faults,
1223 * causing us to "sleep" here for a while. To handle this copy in all
1224 * the data we need now, into a local buffer. Then when we got it all
1225 * copy it into the TX buffer.
1227 chbuf
= (unsigned char *) buf
;
1229 head
= portp
->tx
.head
;
1230 tail
= portp
->tx
.tail
;
1232 len
= STL_TXBUFSIZE
- (head
- tail
) - 1;
1233 stlen
= STL_TXBUFSIZE
- (head
- portp
->tx
.buf
);
1235 len
= tail
- head
- 1;
1239 len
= MIN(len
, count
);
1242 stlen
= MIN(len
, stlen
);
1243 memcpy(head
, chbuf
, stlen
);
1248 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
)) {
1249 head
= portp
->tx
.buf
;
1250 stlen
= tail
- head
;
1253 portp
->tx
.head
= head
;
1255 clear_bit(ASYI_TXLOW
, &portp
->istate
);
1256 stl_startrxtx(portp
, -1, 1);
1261 /*****************************************************************************/
1263 static void stl_putchar(struct tty_struct
*tty
, unsigned char ch
)
1270 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty
, (int) ch
);
1273 if (tty
== (struct tty_struct
*) NULL
)
1275 portp
= tty
->driver_data
;
1276 if (portp
== (stlport_t
*) NULL
)
1278 if (portp
->tx
.buf
== (char *) NULL
)
1281 head
= portp
->tx
.head
;
1282 tail
= portp
->tx
.tail
;
1284 len
= (head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
)) : (tail
- head
);
1289 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
1290 head
= portp
->tx
.buf
;
1292 portp
->tx
.head
= head
;
1295 /*****************************************************************************/
1298 * If there are any characters in the buffer then make sure that TX
1299 * interrupts are on and get'em out. Normally used after the putchar
1300 * routine has been called.
1303 static void stl_flushchars(struct tty_struct
*tty
)
1308 printk("stl_flushchars(tty=%x)\n", (int) tty
);
1311 if (tty
== (struct tty_struct
*) NULL
)
1313 portp
= tty
->driver_data
;
1314 if (portp
== (stlport_t
*) NULL
)
1316 if (portp
->tx
.buf
== (char *) NULL
)
1320 if (tty
->stopped
|| tty
->hw_stopped
||
1321 (portp
->tx
.head
== portp
->tx
.tail
))
1324 stl_startrxtx(portp
, -1, 1);
1327 /*****************************************************************************/
1329 static int stl_writeroom(struct tty_struct
*tty
)
1335 printk("stl_writeroom(tty=%x)\n", (int) tty
);
1338 if (tty
== (struct tty_struct
*) NULL
)
1340 portp
= tty
->driver_data
;
1341 if (portp
== (stlport_t
*) NULL
)
1343 if (portp
->tx
.buf
== (char *) NULL
)
1346 head
= portp
->tx
.head
;
1347 tail
= portp
->tx
.tail
;
1348 return ((head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
) - 1) : (tail
- head
- 1));
1351 /*****************************************************************************/
1354 * Return number of chars in the TX buffer. Normally we would just
1355 * calculate the number of chars in the buffer and return that, but if
1356 * the buffer is empty and TX interrupts are still on then we return
1357 * that the buffer still has 1 char in it. This way whoever called us
1358 * will not think that ALL chars have drained - since the UART still
1359 * must have some chars in it (we are busy after all).
1362 static int stl_charsinbuffer(struct tty_struct
*tty
)
1369 printk("stl_charsinbuffer(tty=%x)\n", (int) tty
);
1372 if (tty
== (struct tty_struct
*) NULL
)
1374 portp
= tty
->driver_data
;
1375 if (portp
== (stlport_t
*) NULL
)
1377 if (portp
->tx
.buf
== (char *) NULL
)
1380 head
= portp
->tx
.head
;
1381 tail
= portp
->tx
.tail
;
1382 size
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
1383 if ((size
== 0) && test_bit(ASYI_TXBUSY
, &portp
->istate
))
1388 /*****************************************************************************/
1391 * Generate the serial struct info.
1394 static int stl_getserial(stlport_t
*portp
, struct serial_struct __user
*sp
)
1396 struct serial_struct sio
;
1400 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
1403 memset(&sio
, 0, sizeof(struct serial_struct
));
1404 sio
.line
= portp
->portnr
;
1405 sio
.port
= portp
->ioaddr
;
1406 sio
.flags
= portp
->flags
;
1407 sio
.baud_base
= portp
->baud_base
;
1408 sio
.close_delay
= portp
->close_delay
;
1409 sio
.closing_wait
= portp
->closing_wait
;
1410 sio
.custom_divisor
= portp
->custom_divisor
;
1412 if (portp
->uartp
== &stl_cd1400uart
) {
1413 sio
.type
= PORT_CIRRUS
;
1414 sio
.xmit_fifo_size
= CD1400_TXFIFOSIZE
;
1416 sio
.type
= PORT_UNKNOWN
;
1417 sio
.xmit_fifo_size
= SC26198_TXFIFOSIZE
;
1420 brdp
= stl_brds
[portp
->brdnr
];
1421 if (brdp
!= (stlbrd_t
*) NULL
)
1422 sio
.irq
= brdp
->irq
;
1424 return copy_to_user(sp
, &sio
, sizeof(struct serial_struct
)) ? -EFAULT
: 0;
1427 /*****************************************************************************/
1430 * Set port according to the serial struct info.
1431 * At this point we do not do any auto-configure stuff, so we will
1432 * just quietly ignore any requests to change irq, etc.
1435 static int stl_setserial(stlport_t
*portp
, struct serial_struct __user
*sp
)
1437 struct serial_struct sio
;
1440 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
1443 if (copy_from_user(&sio
, sp
, sizeof(struct serial_struct
)))
1445 if (!capable(CAP_SYS_ADMIN
)) {
1446 if ((sio
.baud_base
!= portp
->baud_base
) ||
1447 (sio
.close_delay
!= portp
->close_delay
) ||
1448 ((sio
.flags
& ~ASYNC_USR_MASK
) !=
1449 (portp
->flags
& ~ASYNC_USR_MASK
)))
1453 portp
->flags
= (portp
->flags
& ~ASYNC_USR_MASK
) |
1454 (sio
.flags
& ASYNC_USR_MASK
);
1455 portp
->baud_base
= sio
.baud_base
;
1456 portp
->close_delay
= sio
.close_delay
;
1457 portp
->closing_wait
= sio
.closing_wait
;
1458 portp
->custom_divisor
= sio
.custom_divisor
;
1459 stl_setport(portp
, portp
->tty
->termios
);
1463 /*****************************************************************************/
1465 static int stl_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1469 if (tty
== (struct tty_struct
*) NULL
)
1471 portp
= tty
->driver_data
;
1472 if (portp
== (stlport_t
*) NULL
)
1474 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1477 return stl_getsignals(portp
);
1480 static int stl_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1481 unsigned int set
, unsigned int clear
)
1484 int rts
= -1, dtr
= -1;
1486 if (tty
== (struct tty_struct
*) NULL
)
1488 portp
= tty
->driver_data
;
1489 if (portp
== (stlport_t
*) NULL
)
1491 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1494 if (set
& TIOCM_RTS
)
1496 if (set
& TIOCM_DTR
)
1498 if (clear
& TIOCM_RTS
)
1500 if (clear
& TIOCM_DTR
)
1503 stl_setsignals(portp
, dtr
, rts
);
1507 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1512 void __user
*argp
= (void __user
*)arg
;
1515 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1516 (int) tty
, (int) file
, cmd
, (int) arg
);
1519 if (tty
== (struct tty_struct
*) NULL
)
1521 portp
= tty
->driver_data
;
1522 if (portp
== (stlport_t
*) NULL
)
1525 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1526 (cmd
!= COM_GETPORTSTATS
) && (cmd
!= COM_CLRPORTSTATS
)) {
1527 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1535 rc
= put_user(((tty
->termios
->c_cflag
& CLOCAL
) ? 1 : 0),
1536 (unsigned __user
*) argp
);
1539 if (get_user(ival
, (unsigned int __user
*) arg
))
1541 tty
->termios
->c_cflag
=
1542 (tty
->termios
->c_cflag
& ~CLOCAL
) |
1543 (ival
? CLOCAL
: 0);
1546 rc
= stl_getserial(portp
, argp
);
1549 rc
= stl_setserial(portp
, argp
);
1551 case COM_GETPORTSTATS
:
1552 rc
= stl_getportstats(portp
, argp
);
1554 case COM_CLRPORTSTATS
:
1555 rc
= stl_clrportstats(portp
, argp
);
1561 case TIOCSERGSTRUCT
:
1562 case TIOCSERGETMULTI
:
1563 case TIOCSERSETMULTI
:
1572 /*****************************************************************************/
1574 static void stl_settermios(struct tty_struct
*tty
, struct termios
*old
)
1577 struct termios
*tiosp
;
1580 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty
, (int) old
);
1583 if (tty
== (struct tty_struct
*) NULL
)
1585 portp
= tty
->driver_data
;
1586 if (portp
== (stlport_t
*) NULL
)
1589 tiosp
= tty
->termios
;
1590 if ((tiosp
->c_cflag
== old
->c_cflag
) &&
1591 (tiosp
->c_iflag
== old
->c_iflag
))
1594 stl_setport(portp
, tiosp
);
1595 stl_setsignals(portp
, ((tiosp
->c_cflag
& (CBAUD
& ~CBAUDEX
)) ? 1 : 0),
1597 if ((old
->c_cflag
& CRTSCTS
) && ((tiosp
->c_cflag
& CRTSCTS
) == 0)) {
1598 tty
->hw_stopped
= 0;
1601 if (((old
->c_cflag
& CLOCAL
) == 0) && (tiosp
->c_cflag
& CLOCAL
))
1602 wake_up_interruptible(&portp
->open_wait
);
1605 /*****************************************************************************/
1608 * Attempt to flow control who ever is sending us data. Based on termios
1609 * settings use software or/and hardware flow control.
1612 static void stl_throttle(struct tty_struct
*tty
)
1617 printk("stl_throttle(tty=%x)\n", (int) tty
);
1620 if (tty
== (struct tty_struct
*) NULL
)
1622 portp
= tty
->driver_data
;
1623 if (portp
== (stlport_t
*) NULL
)
1625 stl_flowctrl(portp
, 0);
1628 /*****************************************************************************/
1631 * Unflow control the device sending us data...
1634 static void stl_unthrottle(struct tty_struct
*tty
)
1639 printk("stl_unthrottle(tty=%x)\n", (int) tty
);
1642 if (tty
== (struct tty_struct
*) NULL
)
1644 portp
= tty
->driver_data
;
1645 if (portp
== (stlport_t
*) NULL
)
1647 stl_flowctrl(portp
, 1);
1650 /*****************************************************************************/
1653 * Stop the transmitter. Basically to do this we will just turn TX
1657 static void stl_stop(struct tty_struct
*tty
)
1662 printk("stl_stop(tty=%x)\n", (int) tty
);
1665 if (tty
== (struct tty_struct
*) NULL
)
1667 portp
= tty
->driver_data
;
1668 if (portp
== (stlport_t
*) NULL
)
1670 stl_startrxtx(portp
, -1, 0);
1673 /*****************************************************************************/
1676 * Start the transmitter again. Just turn TX interrupts back on.
1679 static void stl_start(struct tty_struct
*tty
)
1684 printk("stl_start(tty=%x)\n", (int) tty
);
1687 if (tty
== (struct tty_struct
*) NULL
)
1689 portp
= tty
->driver_data
;
1690 if (portp
== (stlport_t
*) NULL
)
1692 stl_startrxtx(portp
, -1, 1);
1695 /*****************************************************************************/
1698 * Hangup this port. This is pretty much like closing the port, only
1699 * a little more brutal. No waiting for data to drain. Shutdown the
1700 * port and maybe drop signals.
1703 static void stl_hangup(struct tty_struct
*tty
)
1708 printk("stl_hangup(tty=%x)\n", (int) tty
);
1711 if (tty
== (struct tty_struct
*) NULL
)
1713 portp
= tty
->driver_data
;
1714 if (portp
== (stlport_t
*) NULL
)
1717 portp
->flags
&= ~ASYNC_INITIALIZED
;
1718 stl_disableintrs(portp
);
1719 if (tty
->termios
->c_cflag
& HUPCL
)
1720 stl_setsignals(portp
, 0, 0);
1721 stl_enablerxtx(portp
, 0, 0);
1722 stl_flushbuffer(tty
);
1724 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1725 if (portp
->tx
.buf
!= (char *) NULL
) {
1726 kfree(portp
->tx
.buf
);
1727 portp
->tx
.buf
= (char *) NULL
;
1728 portp
->tx
.head
= (char *) NULL
;
1729 portp
->tx
.tail
= (char *) NULL
;
1731 portp
->tty
= (struct tty_struct
*) NULL
;
1732 portp
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1733 portp
->refcount
= 0;
1734 wake_up_interruptible(&portp
->open_wait
);
1737 /*****************************************************************************/
1739 static void stl_flushbuffer(struct tty_struct
*tty
)
1744 printk("stl_flushbuffer(tty=%x)\n", (int) tty
);
1747 if (tty
== (struct tty_struct
*) NULL
)
1749 portp
= tty
->driver_data
;
1750 if (portp
== (stlport_t
*) NULL
)
1757 /*****************************************************************************/
1759 static void stl_breakctl(struct tty_struct
*tty
, int state
)
1764 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty
, state
);
1767 if (tty
== (struct tty_struct
*) NULL
)
1769 portp
= tty
->driver_data
;
1770 if (portp
== (stlport_t
*) NULL
)
1773 stl_sendbreak(portp
, ((state
== -1) ? 1 : 2));
1776 /*****************************************************************************/
1778 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
)
1784 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty
, timeout
);
1787 if (tty
== (struct tty_struct
*) NULL
)
1789 portp
= tty
->driver_data
;
1790 if (portp
== (stlport_t
*) NULL
)
1795 tend
= jiffies
+ timeout
;
1797 while (stl_datastate(portp
)) {
1798 if (signal_pending(current
))
1800 msleep_interruptible(20);
1801 if (time_after_eq(jiffies
, tend
))
1806 /*****************************************************************************/
1808 static void stl_sendxchar(struct tty_struct
*tty
, char ch
)
1813 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty
, ch
);
1816 if (tty
== (struct tty_struct
*) NULL
)
1818 portp
= tty
->driver_data
;
1819 if (portp
== (stlport_t
*) NULL
)
1822 if (ch
== STOP_CHAR(tty
))
1823 stl_sendflow(portp
, 0);
1824 else if (ch
== START_CHAR(tty
))
1825 stl_sendflow(portp
, 1);
1827 stl_putchar(tty
, ch
);
1830 /*****************************************************************************/
1835 * Format info for a specified port. The line is deliberately limited
1836 * to 80 characters. (If it is too long it will be truncated, if too
1837 * short then padded with spaces).
1840 static int stl_portinfo(stlport_t
*portp
, int portnr
, char *pos
)
1846 sp
+= sprintf(sp
, "%d: uart:%s tx:%d rx:%d",
1847 portnr
, (portp
->hwid
== 1) ? "SC26198" : "CD1400",
1848 (int) portp
->stats
.txtotal
, (int) portp
->stats
.rxtotal
);
1850 if (portp
->stats
.rxframing
)
1851 sp
+= sprintf(sp
, " fe:%d", (int) portp
->stats
.rxframing
);
1852 if (portp
->stats
.rxparity
)
1853 sp
+= sprintf(sp
, " pe:%d", (int) portp
->stats
.rxparity
);
1854 if (portp
->stats
.rxbreaks
)
1855 sp
+= sprintf(sp
, " brk:%d", (int) portp
->stats
.rxbreaks
);
1856 if (portp
->stats
.rxoverrun
)
1857 sp
+= sprintf(sp
, " oe:%d", (int) portp
->stats
.rxoverrun
);
1859 sigs
= stl_getsignals(portp
);
1860 cnt
= sprintf(sp
, "%s%s%s%s%s ",
1861 (sigs
& TIOCM_RTS
) ? "|RTS" : "",
1862 (sigs
& TIOCM_CTS
) ? "|CTS" : "",
1863 (sigs
& TIOCM_DTR
) ? "|DTR" : "",
1864 (sigs
& TIOCM_CD
) ? "|DCD" : "",
1865 (sigs
& TIOCM_DSR
) ? "|DSR" : "");
1869 for (cnt
= (sp
- pos
); (cnt
< (MAXLINE
- 1)); cnt
++)
1872 pos
[(MAXLINE
- 2)] = '+';
1873 pos
[(MAXLINE
- 1)] = '\n';
1878 /*****************************************************************************/
1881 * Port info, read from the /proc file system.
1884 static int stl_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
1889 int brdnr
, panelnr
, portnr
, totalport
;
1894 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1895 "data=%x\n", (int) page
, (int) start
, (int) off
, count
,
1896 (int) eof
, (int) data
);
1904 pos
+= sprintf(pos
, "%s: version %s", stl_drvtitle
,
1906 while (pos
< (page
+ MAXLINE
- 1))
1913 * We scan through for each board, panel and port. The offset is
1914 * calculated on the fly, and irrelevant ports are skipped.
1916 for (brdnr
= 0; (brdnr
< stl_nrbrds
); brdnr
++) {
1917 brdp
= stl_brds
[brdnr
];
1918 if (brdp
== (stlbrd_t
*) NULL
)
1920 if (brdp
->state
== 0)
1923 maxoff
= curoff
+ (brdp
->nrports
* MAXLINE
);
1924 if (off
>= maxoff
) {
1929 totalport
= brdnr
* STL_MAXPORTS
;
1930 for (panelnr
= 0; (panelnr
< brdp
->nrpanels
); panelnr
++) {
1931 panelp
= brdp
->panels
[panelnr
];
1932 if (panelp
== (stlpanel_t
*) NULL
)
1935 maxoff
= curoff
+ (panelp
->nrports
* MAXLINE
);
1936 if (off
>= maxoff
) {
1938 totalport
+= panelp
->nrports
;
1942 for (portnr
= 0; (portnr
< panelp
->nrports
); portnr
++,
1944 portp
= panelp
->ports
[portnr
];
1945 if (portp
== (stlport_t
*) NULL
)
1947 if (off
>= (curoff
+= MAXLINE
))
1949 if ((pos
- page
+ MAXLINE
) > count
)
1951 pos
+= stl_portinfo(portp
, totalport
, pos
);
1960 return (pos
- page
);
1963 /*****************************************************************************/
1966 * All board interrupts are vectored through here first. This code then
1967 * calls off to the approrpriate board interrupt handlers.
1970 static irqreturn_t
stl_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
1972 stlbrd_t
*brdp
= (stlbrd_t
*) dev_id
;
1975 printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp
, irq
,
1979 return IRQ_RETVAL((* brdp
->isr
)(brdp
));
1982 /*****************************************************************************/
1985 * Interrupt service routine for EasyIO board types.
1988 static int stl_eiointr(stlbrd_t
*brdp
)
1991 unsigned int iobase
;
1994 panelp
= brdp
->panels
[0];
1995 iobase
= panelp
->iobase
;
1996 while (inb(brdp
->iostatus
) & EIO_INTRPEND
) {
1998 (* panelp
->isr
)(panelp
, iobase
);
2003 /*****************************************************************************/
2006 * Interrupt service routine for ECH-AT board types.
2009 static int stl_echatintr(stlbrd_t
*brdp
)
2012 unsigned int ioaddr
;
2016 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
2018 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
2020 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2021 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2022 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2023 panelp
= brdp
->bnk2panel
[bnknr
];
2024 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2029 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
2034 /*****************************************************************************/
2037 * Interrupt service routine for ECH-MCA board types.
2040 static int stl_echmcaintr(stlbrd_t
*brdp
)
2043 unsigned int ioaddr
;
2047 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
2049 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2050 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2051 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2052 panelp
= brdp
->bnk2panel
[bnknr
];
2053 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2060 /*****************************************************************************/
2063 * Interrupt service routine for ECH-PCI board types.
2066 static int stl_echpciintr(stlbrd_t
*brdp
)
2069 unsigned int ioaddr
;
2075 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2076 outb(brdp
->bnkpageaddr
[bnknr
], brdp
->ioctrl
);
2077 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2078 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2079 panelp
= brdp
->bnk2panel
[bnknr
];
2080 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2091 /*****************************************************************************/
2094 * Interrupt service routine for ECH-8/64-PCI board types.
2097 static int stl_echpci64intr(stlbrd_t
*brdp
)
2100 unsigned int ioaddr
;
2104 while (inb(brdp
->ioctrl
) & 0x1) {
2106 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2107 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2108 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2109 panelp
= brdp
->bnk2panel
[bnknr
];
2110 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2118 /*****************************************************************************/
2121 * Service an off-level request for some channel.
2123 static void stl_offintr(void *private)
2126 struct tty_struct
*tty
;
2127 unsigned int oldsigs
;
2132 printk("stl_offintr(portp=%x)\n", (int) portp
);
2135 if (portp
== (stlport_t
*) NULL
)
2139 if (tty
== (struct tty_struct
*) NULL
)
2143 if (test_bit(ASYI_TXLOW
, &portp
->istate
)) {
2146 if (test_bit(ASYI_DCDCHANGE
, &portp
->istate
)) {
2147 clear_bit(ASYI_DCDCHANGE
, &portp
->istate
);
2148 oldsigs
= portp
->sigs
;
2149 portp
->sigs
= stl_getsignals(portp
);
2150 if ((portp
->sigs
& TIOCM_CD
) && ((oldsigs
& TIOCM_CD
) == 0))
2151 wake_up_interruptible(&portp
->open_wait
);
2152 if ((oldsigs
& TIOCM_CD
) && ((portp
->sigs
& TIOCM_CD
) == 0)) {
2153 if (portp
->flags
& ASYNC_CHECK_CD
)
2154 tty_hangup(tty
); /* FIXME: module removal race here - AKPM */
2160 /*****************************************************************************/
2163 * Initialize all the ports on a panel.
2166 static int __init
stl_initports(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
2172 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
2175 chipmask
= stl_panelinit(brdp
, panelp
);
2178 * All UART's are initialized (if found!). Now go through and setup
2179 * each ports data structures.
2181 for (i
= 0; (i
< panelp
->nrports
); i
++) {
2182 portp
= (stlport_t
*) stl_memalloc(sizeof(stlport_t
));
2183 if (portp
== (stlport_t
*) NULL
) {
2184 printk("STALLION: failed to allocate memory "
2185 "(size=%d)\n", sizeof(stlport_t
));
2188 memset(portp
, 0, sizeof(stlport_t
));
2190 portp
->magic
= STL_PORTMAGIC
;
2192 portp
->brdnr
= panelp
->brdnr
;
2193 portp
->panelnr
= panelp
->panelnr
;
2194 portp
->uartp
= panelp
->uartp
;
2195 portp
->clk
= brdp
->clk
;
2196 portp
->baud_base
= STL_BAUDBASE
;
2197 portp
->close_delay
= STL_CLOSEDELAY
;
2198 portp
->closing_wait
= 30 * HZ
;
2199 INIT_WORK(&portp
->tqueue
, stl_offintr
, portp
);
2200 init_waitqueue_head(&portp
->open_wait
);
2201 init_waitqueue_head(&portp
->close_wait
);
2202 portp
->stats
.brd
= portp
->brdnr
;
2203 portp
->stats
.panel
= portp
->panelnr
;
2204 portp
->stats
.port
= portp
->portnr
;
2205 panelp
->ports
[i
] = portp
;
2206 stl_portinit(brdp
, panelp
, portp
);
2212 /*****************************************************************************/
2215 * Try to find and initialize an EasyIO board.
2218 static inline int stl_initeio(stlbrd_t
*brdp
)
2221 unsigned int status
;
2226 printk("stl_initeio(brdp=%x)\n", (int) brdp
);
2229 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2230 brdp
->iostatus
= brdp
->ioaddr1
+ 2;
2232 status
= inb(brdp
->iostatus
);
2233 if ((status
& EIO_IDBITMASK
) == EIO_MK3
)
2237 * Handle board specific stuff now. The real difference is PCI
2240 if (brdp
->brdtype
== BRD_EASYIOPCI
) {
2241 brdp
->iosize1
= 0x80;
2242 brdp
->iosize2
= 0x80;
2243 name
= "serial(EIO-PCI)";
2244 outb(0x41, (brdp
->ioaddr2
+ 0x4c));
2247 name
= "serial(EIO)";
2248 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2249 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2250 printk("STALLION: invalid irq=%d for brd=%d\n",
2251 brdp
->irq
, brdp
->brdnr
);
2254 outb((stl_vecmap
[brdp
->irq
] | EIO_0WS
|
2255 ((brdp
->irqtype
) ? EIO_INTLEVEL
: EIO_INTEDGE
)),
2259 if (!request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
)) {
2260 printk(KERN_WARNING
"STALLION: Warning, board %d I/O address "
2261 "%x conflicts with another device\n", brdp
->brdnr
,
2266 if (brdp
->iosize2
> 0)
2267 if (!request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
)) {
2268 printk(KERN_WARNING
"STALLION: Warning, board %d I/O "
2269 "address %x conflicts with another device\n",
2270 brdp
->brdnr
, brdp
->ioaddr2
);
2271 printk(KERN_WARNING
"STALLION: Warning, also "
2272 "releasing board %d I/O address %x \n",
2273 brdp
->brdnr
, brdp
->ioaddr1
);
2274 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
2279 * Everything looks OK, so let's go ahead and probe for the hardware.
2281 brdp
->clk
= CD1400_CLK
;
2282 brdp
->isr
= stl_eiointr
;
2284 switch (status
& EIO_IDBITMASK
) {
2286 brdp
->clk
= CD1400_CLK8M
;
2296 switch (status
& EIO_BRDMASK
) {
2315 * We have verified that the board is actually present, so now we
2316 * can complete the setup.
2319 panelp
= (stlpanel_t
*) stl_memalloc(sizeof(stlpanel_t
));
2320 if (panelp
== (stlpanel_t
*) NULL
) {
2321 printk(KERN_WARNING
"STALLION: failed to allocate memory "
2322 "(size=%d)\n", sizeof(stlpanel_t
));
2325 memset(panelp
, 0, sizeof(stlpanel_t
));
2327 panelp
->magic
= STL_PANELMAGIC
;
2328 panelp
->brdnr
= brdp
->brdnr
;
2329 panelp
->panelnr
= 0;
2330 panelp
->nrports
= brdp
->nrports
;
2331 panelp
->iobase
= brdp
->ioaddr1
;
2332 panelp
->hwid
= status
;
2333 if ((status
& EIO_IDBITMASK
) == EIO_MK3
) {
2334 panelp
->uartp
= (void *) &stl_sc26198uart
;
2335 panelp
->isr
= stl_sc26198intr
;
2337 panelp
->uartp
= (void *) &stl_cd1400uart
;
2338 panelp
->isr
= stl_cd1400eiointr
;
2341 brdp
->panels
[0] = panelp
;
2343 brdp
->state
|= BRD_FOUND
;
2344 brdp
->hwid
= status
;
2345 if (request_irq(brdp
->irq
, stl_intr
, SA_SHIRQ
, name
, brdp
) != 0) {
2346 printk("STALLION: failed to register interrupt "
2347 "routine for %s irq=%d\n", name
, brdp
->irq
);
2355 /*****************************************************************************/
2358 * Try to find an ECH board and initialize it. This code is capable of
2359 * dealing with all types of ECH board.
2362 static inline int stl_initech(stlbrd_t
*brdp
)
2365 unsigned int status
, nxtid
, ioaddr
, conflict
;
2366 int panelnr
, banknr
, i
;
2370 printk("stl_initech(brdp=%x)\n", (int) brdp
);
2377 * Set up the initial board register contents for boards. This varies a
2378 * bit between the different board types. So we need to handle each
2379 * separately. Also do a check that the supplied IRQ is good.
2381 switch (brdp
->brdtype
) {
2384 brdp
->isr
= stl_echatintr
;
2385 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2386 brdp
->iostatus
= brdp
->ioaddr1
+ 1;
2387 status
= inb(brdp
->iostatus
);
2388 if ((status
& ECH_IDBITMASK
) != ECH_ID
)
2390 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2391 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2392 printk("STALLION: invalid irq=%d for brd=%d\n",
2393 brdp
->irq
, brdp
->brdnr
);
2396 status
= ((brdp
->ioaddr2
& ECH_ADDR2MASK
) >> 1);
2397 status
|= (stl_vecmap
[brdp
->irq
] << 1);
2398 outb((status
| ECH_BRDRESET
), brdp
->ioaddr1
);
2399 brdp
->ioctrlval
= ECH_INTENABLE
|
2400 ((brdp
->irqtype
) ? ECH_INTLEVEL
: ECH_INTEDGE
);
2401 for (i
= 0; (i
< 10); i
++)
2402 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
2405 name
= "serial(EC8/32)";
2406 outb(status
, brdp
->ioaddr1
);
2410 brdp
->isr
= stl_echmcaintr
;
2411 brdp
->ioctrl
= brdp
->ioaddr1
+ 0x20;
2412 brdp
->iostatus
= brdp
->ioctrl
;
2413 status
= inb(brdp
->iostatus
);
2414 if ((status
& ECH_IDBITMASK
) != ECH_ID
)
2416 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2417 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2418 printk("STALLION: invalid irq=%d for brd=%d\n",
2419 brdp
->irq
, brdp
->brdnr
);
2422 outb(ECHMC_BRDRESET
, brdp
->ioctrl
);
2423 outb(ECHMC_INTENABLE
, brdp
->ioctrl
);
2425 name
= "serial(EC8/32-MC)";
2429 brdp
->isr
= stl_echpciintr
;
2430 brdp
->ioctrl
= brdp
->ioaddr1
+ 2;
2433 name
= "serial(EC8/32-PCI)";
2437 brdp
->isr
= stl_echpci64intr
;
2438 brdp
->ioctrl
= brdp
->ioaddr2
+ 0x40;
2439 outb(0x43, (brdp
->ioaddr1
+ 0x4c));
2440 brdp
->iosize1
= 0x80;
2441 brdp
->iosize2
= 0x80;
2442 name
= "serial(EC8/64-PCI)";
2446 printk("STALLION: unknown board type=%d\n", brdp
->brdtype
);
2452 * Check boards for possible IO address conflicts and return fail status
2453 * if an IO conflict found.
2455 if (!request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
)) {
2456 printk(KERN_WARNING
"STALLION: Warning, board %d I/O address "
2457 "%x conflicts with another device\n", brdp
->brdnr
,
2462 if (brdp
->iosize2
> 0)
2463 if (!request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
)) {
2464 printk(KERN_WARNING
"STALLION: Warning, board %d I/O "
2465 "address %x conflicts with another device\n",
2466 brdp
->brdnr
, brdp
->ioaddr2
);
2467 printk(KERN_WARNING
"STALLION: Warning, also "
2468 "releasing board %d I/O address %x \n",
2469 brdp
->brdnr
, brdp
->ioaddr1
);
2470 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
2475 * Scan through the secondary io address space looking for panels.
2476 * As we find'em allocate and initialize panel structures for each.
2478 brdp
->clk
= CD1400_CLK
;
2479 brdp
->hwid
= status
;
2481 ioaddr
= brdp
->ioaddr2
;
2486 for (i
= 0; (i
< STL_MAXPANELS
); i
++) {
2487 if (brdp
->brdtype
== BRD_ECHPCI
) {
2488 outb(nxtid
, brdp
->ioctrl
);
2489 ioaddr
= brdp
->ioaddr2
;
2491 status
= inb(ioaddr
+ ECH_PNLSTATUS
);
2492 if ((status
& ECH_PNLIDMASK
) != nxtid
)
2494 panelp
= (stlpanel_t
*) stl_memalloc(sizeof(stlpanel_t
));
2495 if (panelp
== (stlpanel_t
*) NULL
) {
2496 printk("STALLION: failed to allocate memory "
2497 "(size=%d)\n", sizeof(stlpanel_t
));
2500 memset(panelp
, 0, sizeof(stlpanel_t
));
2501 panelp
->magic
= STL_PANELMAGIC
;
2502 panelp
->brdnr
= brdp
->brdnr
;
2503 panelp
->panelnr
= panelnr
;
2504 panelp
->iobase
= ioaddr
;
2505 panelp
->pagenr
= nxtid
;
2506 panelp
->hwid
= status
;
2507 brdp
->bnk2panel
[banknr
] = panelp
;
2508 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2509 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ ECH_PNLSTATUS
;
2511 if (status
& ECH_PNLXPID
) {
2512 panelp
->uartp
= (void *) &stl_sc26198uart
;
2513 panelp
->isr
= stl_sc26198intr
;
2514 if (status
& ECH_PNL16PORT
) {
2515 panelp
->nrports
= 16;
2516 brdp
->bnk2panel
[banknr
] = panelp
;
2517 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2518 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ 4 +
2521 panelp
->nrports
= 8;
2524 panelp
->uartp
= (void *) &stl_cd1400uart
;
2525 panelp
->isr
= stl_cd1400echintr
;
2526 if (status
& ECH_PNL16PORT
) {
2527 panelp
->nrports
= 16;
2528 panelp
->ackmask
= 0x80;
2529 if (brdp
->brdtype
!= BRD_ECHPCI
)
2530 ioaddr
+= EREG_BANKSIZE
;
2531 brdp
->bnk2panel
[banknr
] = panelp
;
2532 brdp
->bnkpageaddr
[banknr
] = ++nxtid
;
2533 brdp
->bnkstataddr
[banknr
++] = ioaddr
+
2536 panelp
->nrports
= 8;
2537 panelp
->ackmask
= 0xc0;
2542 ioaddr
+= EREG_BANKSIZE
;
2543 brdp
->nrports
+= panelp
->nrports
;
2544 brdp
->panels
[panelnr
++] = panelp
;
2545 if ((brdp
->brdtype
!= BRD_ECHPCI
) &&
2546 (ioaddr
>= (brdp
->ioaddr2
+ brdp
->iosize2
)))
2550 brdp
->nrpanels
= panelnr
;
2551 brdp
->nrbnks
= banknr
;
2552 if (brdp
->brdtype
== BRD_ECH
)
2553 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
2555 brdp
->state
|= BRD_FOUND
;
2556 if (request_irq(brdp
->irq
, stl_intr
, SA_SHIRQ
, name
, brdp
) != 0) {
2557 printk("STALLION: failed to register interrupt "
2558 "routine for %s irq=%d\n", name
, brdp
->irq
);
2567 /*****************************************************************************/
2570 * Initialize and configure the specified board.
2571 * Scan through all the boards in the configuration and see what we
2572 * can find. Handle EIO and the ECH boards a little differently here
2573 * since the initial search and setup is very different.
2576 static int __init
stl_brdinit(stlbrd_t
*brdp
)
2581 printk("stl_brdinit(brdp=%x)\n", (int) brdp
);
2584 switch (brdp
->brdtype
) {
2596 printk("STALLION: board=%d is unknown board type=%d\n",
2597 brdp
->brdnr
, brdp
->brdtype
);
2601 stl_brds
[brdp
->brdnr
] = brdp
;
2602 if ((brdp
->state
& BRD_FOUND
) == 0) {
2603 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2604 stl_brdnames
[brdp
->brdtype
], brdp
->brdnr
,
2605 brdp
->ioaddr1
, brdp
->irq
);
2609 for (i
= 0; (i
< STL_MAXPANELS
); i
++)
2610 if (brdp
->panels
[i
] != (stlpanel_t
*) NULL
)
2611 stl_initports(brdp
, brdp
->panels
[i
]);
2613 printk("STALLION: %s found, board=%d io=%x irq=%d "
2614 "nrpanels=%d nrports=%d\n", stl_brdnames
[brdp
->brdtype
],
2615 brdp
->brdnr
, brdp
->ioaddr1
, brdp
->irq
, brdp
->nrpanels
,
2620 /*****************************************************************************/
2623 * Find the next available board number that is free.
2626 static inline int stl_getbrdnr(void)
2630 for (i
= 0; (i
< STL_MAXBRDS
); i
++) {
2631 if (stl_brds
[i
] == (stlbrd_t
*) NULL
) {
2632 if (i
>= stl_nrbrds
)
2640 /*****************************************************************************/
2645 * We have a Stallion board. Allocate a board structure and
2646 * initialize it. Read its IO and IRQ resources from PCI
2647 * configuration space.
2650 static inline int stl_initpcibrd(int brdtype
, struct pci_dev
*devp
)
2655 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype
,
2656 devp
->bus
->number
, devp
->devfn
);
2659 if (pci_enable_device(devp
))
2661 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
2663 if ((brdp
->brdnr
= stl_getbrdnr()) < 0) {
2664 printk("STALLION: too many boards found, "
2665 "maximum supported %d\n", STL_MAXBRDS
);
2668 brdp
->brdtype
= brdtype
;
2671 * Different Stallion boards use the BAR registers in different ways,
2672 * so set up io addresses based on board type.
2675 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__
, __LINE__
,
2676 pci_resource_start(devp
, 0), pci_resource_start(devp
, 1),
2677 pci_resource_start(devp
, 2), pci_resource_start(devp
, 3), devp
->irq
);
2681 * We have all resources from the board, so let's setup the actual
2682 * board structure now.
2686 brdp
->ioaddr2
= pci_resource_start(devp
, 0);
2687 brdp
->ioaddr1
= pci_resource_start(devp
, 1);
2690 brdp
->ioaddr2
= pci_resource_start(devp
, 2);
2691 brdp
->ioaddr1
= pci_resource_start(devp
, 1);
2694 brdp
->ioaddr1
= pci_resource_start(devp
, 2);
2695 brdp
->ioaddr2
= pci_resource_start(devp
, 1);
2698 printk("STALLION: unknown PCI board type=%d\n", brdtype
);
2702 brdp
->irq
= devp
->irq
;
2708 /*****************************************************************************/
2711 * Find all Stallion PCI boards that might be installed. Initialize each
2712 * one as it is found.
2716 static inline int stl_findpcibrds(void)
2718 struct pci_dev
*dev
= NULL
;
2722 printk("stl_findpcibrds()\n");
2725 for (i
= 0; (i
< stl_nrpcibrds
); i
++)
2726 while ((dev
= pci_find_device(stl_pcibrds
[i
].vendid
,
2727 stl_pcibrds
[i
].devid
, dev
))) {
2730 * Found a device on the PCI bus that has our vendor and
2731 * device ID. Need to check now that it is really us.
2733 if ((dev
->class >> 8) == PCI_CLASS_STORAGE_IDE
)
2736 rc
= stl_initpcibrd(stl_pcibrds
[i
].brdtype
, dev
);
2746 /*****************************************************************************/
2749 * Scan through all the boards in the configuration and see what we
2750 * can find. Handle EIO and the ECH boards a little differently here
2751 * since the initial search and setup is too different.
2754 static inline int stl_initbrds(void)
2761 printk("stl_initbrds()\n");
2764 if (stl_nrbrds
> STL_MAXBRDS
) {
2765 printk("STALLION: too many boards in configuration table, "
2766 "truncating to %d\n", STL_MAXBRDS
);
2767 stl_nrbrds
= STL_MAXBRDS
;
2771 * Firstly scan the list of static boards configured. Allocate
2772 * resources and initialize the boards as found.
2774 for (i
= 0; (i
< stl_nrbrds
); i
++) {
2775 confp
= &stl_brdconf
[i
];
2776 stl_parsebrd(confp
, stl_brdsp
[i
]);
2777 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
2780 brdp
->brdtype
= confp
->brdtype
;
2781 brdp
->ioaddr1
= confp
->ioaddr1
;
2782 brdp
->ioaddr2
= confp
->ioaddr2
;
2783 brdp
->irq
= confp
->irq
;
2784 brdp
->irqtype
= confp
->irqtype
;
2789 * Find any dynamically supported boards. That is via module load
2790 * line options or auto-detected on the PCI bus.
2800 /*****************************************************************************/
2803 * Return the board stats structure to user app.
2806 static int stl_getbrdstats(combrd_t __user
*bp
)
2812 if (copy_from_user(&stl_brdstats
, bp
, sizeof(combrd_t
)))
2814 if (stl_brdstats
.brd
>= STL_MAXBRDS
)
2816 brdp
= stl_brds
[stl_brdstats
.brd
];
2817 if (brdp
== (stlbrd_t
*) NULL
)
2820 memset(&stl_brdstats
, 0, sizeof(combrd_t
));
2821 stl_brdstats
.brd
= brdp
->brdnr
;
2822 stl_brdstats
.type
= brdp
->brdtype
;
2823 stl_brdstats
.hwid
= brdp
->hwid
;
2824 stl_brdstats
.state
= brdp
->state
;
2825 stl_brdstats
.ioaddr
= brdp
->ioaddr1
;
2826 stl_brdstats
.ioaddr2
= brdp
->ioaddr2
;
2827 stl_brdstats
.irq
= brdp
->irq
;
2828 stl_brdstats
.nrpanels
= brdp
->nrpanels
;
2829 stl_brdstats
.nrports
= brdp
->nrports
;
2830 for (i
= 0; (i
< brdp
->nrpanels
); i
++) {
2831 panelp
= brdp
->panels
[i
];
2832 stl_brdstats
.panels
[i
].panel
= i
;
2833 stl_brdstats
.panels
[i
].hwid
= panelp
->hwid
;
2834 stl_brdstats
.panels
[i
].nrports
= panelp
->nrports
;
2837 return copy_to_user(bp
, &stl_brdstats
, sizeof(combrd_t
)) ? -EFAULT
: 0;
2840 /*****************************************************************************/
2843 * Resolve the referenced port number into a port struct pointer.
2846 static stlport_t
*stl_getport(int brdnr
, int panelnr
, int portnr
)
2851 if ((brdnr
< 0) || (brdnr
>= STL_MAXBRDS
))
2852 return((stlport_t
*) NULL
);
2853 brdp
= stl_brds
[brdnr
];
2854 if (brdp
== (stlbrd_t
*) NULL
)
2855 return((stlport_t
*) NULL
);
2856 if ((panelnr
< 0) || (panelnr
>= brdp
->nrpanels
))
2857 return((stlport_t
*) NULL
);
2858 panelp
= brdp
->panels
[panelnr
];
2859 if (panelp
== (stlpanel_t
*) NULL
)
2860 return((stlport_t
*) NULL
);
2861 if ((portnr
< 0) || (portnr
>= panelp
->nrports
))
2862 return((stlport_t
*) NULL
);
2863 return(panelp
->ports
[portnr
]);
2866 /*****************************************************************************/
2869 * Return the port stats structure to user app. A NULL port struct
2870 * pointer passed in means that we need to find out from the app
2871 * what port to get stats for (used through board control device).
2874 static int stl_getportstats(stlport_t
*portp
, comstats_t __user
*cp
)
2876 unsigned char *head
, *tail
;
2877 unsigned long flags
;
2880 if (copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
)))
2882 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
2884 if (portp
== (stlport_t
*) NULL
)
2888 portp
->stats
.state
= portp
->istate
;
2889 portp
->stats
.flags
= portp
->flags
;
2890 portp
->stats
.hwid
= portp
->hwid
;
2892 portp
->stats
.ttystate
= 0;
2893 portp
->stats
.cflags
= 0;
2894 portp
->stats
.iflags
= 0;
2895 portp
->stats
.oflags
= 0;
2896 portp
->stats
.lflags
= 0;
2897 portp
->stats
.rxbuffered
= 0;
2901 if (portp
->tty
!= (struct tty_struct
*) NULL
) {
2902 if (portp
->tty
->driver_data
== portp
) {
2903 portp
->stats
.ttystate
= portp
->tty
->flags
;
2904 /* No longer available as a statistic */
2905 portp
->stats
.rxbuffered
= 1; /*portp->tty->flip.count; */
2906 if (portp
->tty
->termios
!= (struct termios
*) NULL
) {
2907 portp
->stats
.cflags
= portp
->tty
->termios
->c_cflag
;
2908 portp
->stats
.iflags
= portp
->tty
->termios
->c_iflag
;
2909 portp
->stats
.oflags
= portp
->tty
->termios
->c_oflag
;
2910 portp
->stats
.lflags
= portp
->tty
->termios
->c_lflag
;
2914 restore_flags(flags
);
2916 head
= portp
->tx
.head
;
2917 tail
= portp
->tx
.tail
;
2918 portp
->stats
.txbuffered
= ((head
>= tail
) ? (head
- tail
) :
2919 (STL_TXBUFSIZE
- (tail
- head
)));
2921 portp
->stats
.signals
= (unsigned long) stl_getsignals(portp
);
2923 return copy_to_user(cp
, &portp
->stats
,
2924 sizeof(comstats_t
)) ? -EFAULT
: 0;
2927 /*****************************************************************************/
2930 * Clear the port stats structure. We also return it zeroed out...
2933 static int stl_clrportstats(stlport_t
*portp
, comstats_t __user
*cp
)
2936 if (copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
)))
2938 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
2940 if (portp
== (stlport_t
*) NULL
)
2944 memset(&portp
->stats
, 0, sizeof(comstats_t
));
2945 portp
->stats
.brd
= portp
->brdnr
;
2946 portp
->stats
.panel
= portp
->panelnr
;
2947 portp
->stats
.port
= portp
->portnr
;
2948 return copy_to_user(cp
, &portp
->stats
,
2949 sizeof(comstats_t
)) ? -EFAULT
: 0;
2952 /*****************************************************************************/
2955 * Return the entire driver ports structure to a user app.
2958 static int stl_getportstruct(stlport_t __user
*arg
)
2962 if (copy_from_user(&stl_dummyport
, arg
, sizeof(stlport_t
)))
2964 portp
= stl_getport(stl_dummyport
.brdnr
, stl_dummyport
.panelnr
,
2965 stl_dummyport
.portnr
);
2968 return copy_to_user(arg
, portp
, sizeof(stlport_t
)) ? -EFAULT
: 0;
2971 /*****************************************************************************/
2974 * Return the entire driver board structure to a user app.
2977 static int stl_getbrdstruct(stlbrd_t __user
*arg
)
2981 if (copy_from_user(&stl_dummybrd
, arg
, sizeof(stlbrd_t
)))
2983 if ((stl_dummybrd
.brdnr
< 0) || (stl_dummybrd
.brdnr
>= STL_MAXBRDS
))
2985 brdp
= stl_brds
[stl_dummybrd
.brdnr
];
2988 return copy_to_user(arg
, brdp
, sizeof(stlbrd_t
)) ? -EFAULT
: 0;
2991 /*****************************************************************************/
2994 * The "staliomem" device is also required to do some special operations
2995 * on the board and/or ports. In this driver it is mostly used for stats
2999 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
)
3002 void __user
*argp
= (void __user
*)arg
;
3005 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip
,
3006 (int) fp
, cmd
, (int) arg
);
3010 if (brdnr
>= STL_MAXBRDS
)
3015 case COM_GETPORTSTATS
:
3016 rc
= stl_getportstats(NULL
, argp
);
3018 case COM_CLRPORTSTATS
:
3019 rc
= stl_clrportstats(NULL
, argp
);
3021 case COM_GETBRDSTATS
:
3022 rc
= stl_getbrdstats(argp
);
3025 rc
= stl_getportstruct(argp
);
3028 rc
= stl_getbrdstruct(argp
);
3038 static struct tty_operations stl_ops
= {
3042 .put_char
= stl_putchar
,
3043 .flush_chars
= stl_flushchars
,
3044 .write_room
= stl_writeroom
,
3045 .chars_in_buffer
= stl_charsinbuffer
,
3047 .set_termios
= stl_settermios
,
3048 .throttle
= stl_throttle
,
3049 .unthrottle
= stl_unthrottle
,
3052 .hangup
= stl_hangup
,
3053 .flush_buffer
= stl_flushbuffer
,
3054 .break_ctl
= stl_breakctl
,
3055 .wait_until_sent
= stl_waituntilsent
,
3056 .send_xchar
= stl_sendxchar
,
3057 .read_proc
= stl_readproc
,
3058 .tiocmget
= stl_tiocmget
,
3059 .tiocmset
= stl_tiocmset
,
3062 /*****************************************************************************/
3064 static int __init
stl_init(void)
3067 printk(KERN_INFO
"%s: version %s\n", stl_drvtitle
, stl_drvversion
);
3071 stl_serial
= alloc_tty_driver(STL_MAXBRDS
* STL_MAXPORTS
);
3076 * Allocate a temporary write buffer.
3078 stl_tmpwritebuf
= (char *) stl_memalloc(STL_TXBUFSIZE
);
3079 if (stl_tmpwritebuf
== (char *) NULL
)
3080 printk("STALLION: failed to allocate memory (size=%d)\n",
3084 * Set up a character driver for per board stuff. This is mainly used
3085 * to do stats ioctls on the ports.
3087 if (register_chrdev(STL_SIOMEMMAJOR
, "staliomem", &stl_fsiomem
))
3088 printk("STALLION: failed to register serial board device\n");
3089 devfs_mk_dir("staliomem");
3091 stallion_class
= class_create(THIS_MODULE
, "staliomem");
3092 for (i
= 0; i
< 4; i
++) {
3093 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR
, i
),
3094 S_IFCHR
|S_IRUSR
|S_IWUSR
,
3096 class_device_create(stallion_class
, NULL
,
3097 MKDEV(STL_SIOMEMMAJOR
, i
), NULL
,
3101 stl_serial
->owner
= THIS_MODULE
;
3102 stl_serial
->driver_name
= stl_drvname
;
3103 stl_serial
->name
= "ttyE";
3104 stl_serial
->devfs_name
= "tts/E";
3105 stl_serial
->major
= STL_SERIALMAJOR
;
3106 stl_serial
->minor_start
= 0;
3107 stl_serial
->type
= TTY_DRIVER_TYPE_SERIAL
;
3108 stl_serial
->subtype
= SERIAL_TYPE_NORMAL
;
3109 stl_serial
->init_termios
= stl_deftermios
;
3110 stl_serial
->flags
= TTY_DRIVER_REAL_RAW
;
3111 tty_set_operations(stl_serial
, &stl_ops
);
3113 if (tty_register_driver(stl_serial
)) {
3114 put_tty_driver(stl_serial
);
3115 printk("STALLION: failed to register serial driver\n");
3122 /*****************************************************************************/
3123 /* CD1400 HARDWARE FUNCTIONS */
3124 /*****************************************************************************/
3127 * These functions get/set/update the registers of the cd1400 UARTs.
3128 * Access to the cd1400 registers is via an address/data io port pair.
3129 * (Maybe should make this inline...)
3132 static int stl_cd1400getreg(stlport_t
*portp
, int regnr
)
3134 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3135 return inb(portp
->ioaddr
+ EREG_DATA
);
3138 static void stl_cd1400setreg(stlport_t
*portp
, int regnr
, int value
)
3140 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3141 outb(value
, portp
->ioaddr
+ EREG_DATA
);
3144 static int stl_cd1400updatereg(stlport_t
*portp
, int regnr
, int value
)
3146 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3147 if (inb(portp
->ioaddr
+ EREG_DATA
) != value
) {
3148 outb(value
, portp
->ioaddr
+ EREG_DATA
);
3154 /*****************************************************************************/
3157 * Inbitialize the UARTs in a panel. We don't care what sort of board
3158 * these ports are on - since the port io registers are almost
3159 * identical when dealing with ports.
3162 static int stl_cd1400panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
3166 int nrchips
, uartaddr
, ioaddr
;
3169 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
3172 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
3175 * Check that each chip is present and started up OK.
3178 nrchips
= panelp
->nrports
/ CD1400_PORTS
;
3179 for (i
= 0; (i
< nrchips
); i
++) {
3180 if (brdp
->brdtype
== BRD_ECHPCI
) {
3181 outb((panelp
->pagenr
+ (i
>> 1)), brdp
->ioctrl
);
3182 ioaddr
= panelp
->iobase
;
3184 ioaddr
= panelp
->iobase
+ (EREG_BANKSIZE
* (i
>> 1));
3186 uartaddr
= (i
& 0x01) ? 0x080 : 0;
3187 outb((GFRCR
+ uartaddr
), ioaddr
);
3188 outb(0, (ioaddr
+ EREG_DATA
));
3189 outb((CCR
+ uartaddr
), ioaddr
);
3190 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
3191 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
3192 outb((GFRCR
+ uartaddr
), ioaddr
);
3193 for (j
= 0; (j
< CCR_MAXWAIT
); j
++) {
3194 if ((gfrcr
= inb(ioaddr
+ EREG_DATA
)) != 0)
3197 if ((j
>= CCR_MAXWAIT
) || (gfrcr
< 0x40) || (gfrcr
> 0x60)) {
3198 printk("STALLION: cd1400 not responding, "
3199 "brd=%d panel=%d chip=%d\n",
3200 panelp
->brdnr
, panelp
->panelnr
, i
);
3203 chipmask
|= (0x1 << i
);
3204 outb((PPR
+ uartaddr
), ioaddr
);
3205 outb(PPR_SCALAR
, (ioaddr
+ EREG_DATA
));
3208 BRDDISABLE(panelp
->brdnr
);
3212 /*****************************************************************************/
3215 * Initialize hardware specific port registers.
3218 static void stl_cd1400portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
3221 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3222 (int) brdp
, (int) panelp
, (int) portp
);
3225 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
3226 (portp
== (stlport_t
*) NULL
))
3229 portp
->ioaddr
= panelp
->iobase
+ (((brdp
->brdtype
== BRD_ECHPCI
) ||
3230 (portp
->portnr
< 8)) ? 0 : EREG_BANKSIZE
);
3231 portp
->uartaddr
= (portp
->portnr
& 0x04) << 5;
3232 portp
->pagenr
= panelp
->pagenr
+ (portp
->portnr
>> 3);
3234 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3235 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3236 stl_cd1400setreg(portp
, LIVR
, (portp
->portnr
<< 3));
3237 portp
->hwid
= stl_cd1400getreg(portp
, GFRCR
);
3238 BRDDISABLE(portp
->brdnr
);
3241 /*****************************************************************************/
3244 * Wait for the command register to be ready. We will poll this,
3245 * since it won't usually take too long to be ready.
3248 static void stl_cd1400ccrwait(stlport_t
*portp
)
3252 for (i
= 0; (i
< CCR_MAXWAIT
); i
++) {
3253 if (stl_cd1400getreg(portp
, CCR
) == 0) {
3258 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3259 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
3262 /*****************************************************************************/
3265 * Set up the cd1400 registers for a port based on the termios port
3269 static void stl_cd1400setport(stlport_t
*portp
, struct termios
*tiosp
)
3272 unsigned long flags
;
3273 unsigned int clkdiv
, baudrate
;
3274 unsigned char cor1
, cor2
, cor3
;
3275 unsigned char cor4
, cor5
, ccr
;
3276 unsigned char srer
, sreron
, sreroff
;
3277 unsigned char mcor1
, mcor2
, rtpr
;
3278 unsigned char clk
, div
;
3294 brdp
= stl_brds
[portp
->brdnr
];
3295 if (brdp
== (stlbrd_t
*) NULL
)
3299 * Set up the RX char ignore mask with those RX error types we
3300 * can ignore. We can get the cd1400 to help us out a little here,
3301 * it will ignore parity errors and breaks for us.
3303 portp
->rxignoremsk
= 0;
3304 if (tiosp
->c_iflag
& IGNPAR
) {
3305 portp
->rxignoremsk
|= (ST_PARITY
| ST_FRAMING
| ST_OVERRUN
);
3306 cor1
|= COR1_PARIGNORE
;
3308 if (tiosp
->c_iflag
& IGNBRK
) {
3309 portp
->rxignoremsk
|= ST_BREAK
;
3310 cor4
|= COR4_IGNBRK
;
3313 portp
->rxmarkmsk
= ST_OVERRUN
;
3314 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
3315 portp
->rxmarkmsk
|= (ST_PARITY
| ST_FRAMING
);
3316 if (tiosp
->c_iflag
& BRKINT
)
3317 portp
->rxmarkmsk
|= ST_BREAK
;
3320 * Go through the char size, parity and stop bits and set all the
3321 * option register appropriately.
3323 switch (tiosp
->c_cflag
& CSIZE
) {
3338 if (tiosp
->c_cflag
& CSTOPB
)
3343 if (tiosp
->c_cflag
& PARENB
) {
3344 if (tiosp
->c_cflag
& PARODD
)
3345 cor1
|= (COR1_PARENB
| COR1_PARODD
);
3347 cor1
|= (COR1_PARENB
| COR1_PAREVEN
);
3349 cor1
|= COR1_PARNONE
;
3353 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3354 * space for hardware flow control and the like. This should be set to
3355 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3356 * really be based on VTIME.
3358 cor3
|= FIFO_RXTHRESHOLD
;
3362 * Calculate the baud rate timers. For now we will just assume that
3363 * the input and output baud are the same. Could have used a baud
3364 * table here, but this way we can generate virtually any baud rate
3367 baudrate
= tiosp
->c_cflag
& CBAUD
;
3368 if (baudrate
& CBAUDEX
) {
3369 baudrate
&= ~CBAUDEX
;
3370 if ((baudrate
< 1) || (baudrate
> 4))
3371 tiosp
->c_cflag
&= ~CBAUDEX
;
3375 baudrate
= stl_baudrates
[baudrate
];
3376 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
3377 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3379 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3381 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3383 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3385 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
3386 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
3388 if (baudrate
> STL_CD1400MAXBAUD
)
3389 baudrate
= STL_CD1400MAXBAUD
;
3392 for (clk
= 0; (clk
< CD1400_NUMCLKS
); clk
++) {
3393 clkdiv
= ((portp
->clk
/ stl_cd1400clkdivs
[clk
]) / baudrate
);
3397 div
= (unsigned char) clkdiv
;
3401 * Check what form of modem signaling is required and set it up.
3403 if ((tiosp
->c_cflag
& CLOCAL
) == 0) {
3406 sreron
|= SRER_MODEM
;
3407 portp
->flags
|= ASYNC_CHECK_CD
;
3409 portp
->flags
&= ~ASYNC_CHECK_CD
;
3413 * Setup cd1400 enhanced modes if we can. In particular we want to
3414 * handle as much of the flow control as possible automatically. As
3415 * well as saving a few CPU cycles it will also greatly improve flow
3416 * control reliability.
3418 if (tiosp
->c_iflag
& IXON
) {
3421 if (tiosp
->c_iflag
& IXANY
)
3425 if (tiosp
->c_cflag
& CRTSCTS
) {
3427 mcor1
|= FIFO_RTSTHRESHOLD
;
3431 * All cd1400 register values calculated so go through and set
3436 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3437 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
3438 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3439 cor1
, cor2
, cor3
, cor4
, cor5
);
3440 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3441 mcor1
, mcor2
, rtpr
, sreron
, sreroff
);
3442 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk
, div
, clk
, div
);
3443 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3444 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
3445 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
3450 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3451 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x3));
3452 srer
= stl_cd1400getreg(portp
, SRER
);
3453 stl_cd1400setreg(portp
, SRER
, 0);
3454 if (stl_cd1400updatereg(portp
, COR1
, cor1
))
3456 if (stl_cd1400updatereg(portp
, COR2
, cor2
))
3458 if (stl_cd1400updatereg(portp
, COR3
, cor3
))
3461 stl_cd1400ccrwait(portp
);
3462 stl_cd1400setreg(portp
, CCR
, CCR_CORCHANGE
);
3464 stl_cd1400setreg(portp
, COR4
, cor4
);
3465 stl_cd1400setreg(portp
, COR5
, cor5
);
3466 stl_cd1400setreg(portp
, MCOR1
, mcor1
);
3467 stl_cd1400setreg(portp
, MCOR2
, mcor2
);
3469 stl_cd1400setreg(portp
, TCOR
, clk
);
3470 stl_cd1400setreg(portp
, TBPR
, div
);
3471 stl_cd1400setreg(portp
, RCOR
, clk
);
3472 stl_cd1400setreg(portp
, RBPR
, div
);
3474 stl_cd1400setreg(portp
, SCHR1
, tiosp
->c_cc
[VSTART
]);
3475 stl_cd1400setreg(portp
, SCHR2
, tiosp
->c_cc
[VSTOP
]);
3476 stl_cd1400setreg(portp
, SCHR3
, tiosp
->c_cc
[VSTART
]);
3477 stl_cd1400setreg(portp
, SCHR4
, tiosp
->c_cc
[VSTOP
]);
3478 stl_cd1400setreg(portp
, RTPR
, rtpr
);
3479 mcor1
= stl_cd1400getreg(portp
, MSVR1
);
3480 if (mcor1
& MSVR1_DCD
)
3481 portp
->sigs
|= TIOCM_CD
;
3483 portp
->sigs
&= ~TIOCM_CD
;
3484 stl_cd1400setreg(portp
, SRER
, ((srer
& ~sreroff
) | sreron
));
3485 BRDDISABLE(portp
->brdnr
);
3486 restore_flags(flags
);
3489 /*****************************************************************************/
3492 * Set the state of the DTR and RTS signals.
3495 static void stl_cd1400setsignals(stlport_t
*portp
, int dtr
, int rts
)
3497 unsigned char msvr1
, msvr2
;
3498 unsigned long flags
;
3501 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3502 (int) portp
, dtr
, rts
);
3514 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3515 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3517 stl_cd1400setreg(portp
, MSVR2
, msvr2
);
3519 stl_cd1400setreg(portp
, MSVR1
, msvr1
);
3520 BRDDISABLE(portp
->brdnr
);
3521 restore_flags(flags
);
3524 /*****************************************************************************/
3527 * Return the state of the signals.
3530 static int stl_cd1400getsignals(stlport_t
*portp
)
3532 unsigned char msvr1
, msvr2
;
3533 unsigned long flags
;
3537 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp
);
3542 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3543 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3544 msvr1
= stl_cd1400getreg(portp
, MSVR1
);
3545 msvr2
= stl_cd1400getreg(portp
, MSVR2
);
3546 BRDDISABLE(portp
->brdnr
);
3547 restore_flags(flags
);
3550 sigs
|= (msvr1
& MSVR1_DCD
) ? TIOCM_CD
: 0;
3551 sigs
|= (msvr1
& MSVR1_CTS
) ? TIOCM_CTS
: 0;
3552 sigs
|= (msvr1
& MSVR1_DTR
) ? TIOCM_DTR
: 0;
3553 sigs
|= (msvr2
& MSVR2_RTS
) ? TIOCM_RTS
: 0;
3555 sigs
|= (msvr1
& MSVR1_RI
) ? TIOCM_RI
: 0;
3556 sigs
|= (msvr1
& MSVR1_DSR
) ? TIOCM_DSR
: 0;
3563 /*****************************************************************************/
3566 * Enable/Disable the Transmitter and/or Receiver.
3569 static void stl_cd1400enablerxtx(stlport_t
*portp
, int rx
, int tx
)
3572 unsigned long flags
;
3575 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3576 (int) portp
, rx
, tx
);
3581 ccr
|= CCR_TXDISABLE
;
3583 ccr
|= CCR_TXENABLE
;
3585 ccr
|= CCR_RXDISABLE
;
3587 ccr
|= CCR_RXENABLE
;
3591 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3592 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3593 stl_cd1400ccrwait(portp
);
3594 stl_cd1400setreg(portp
, CCR
, ccr
);
3595 stl_cd1400ccrwait(portp
);
3596 BRDDISABLE(portp
->brdnr
);
3597 restore_flags(flags
);
3600 /*****************************************************************************/
3603 * Start/stop the Transmitter and/or Receiver.
3606 static void stl_cd1400startrxtx(stlport_t
*portp
, int rx
, int tx
)
3608 unsigned char sreron
, sreroff
;
3609 unsigned long flags
;
3612 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3613 (int) portp
, rx
, tx
);
3619 sreroff
|= (SRER_TXDATA
| SRER_TXEMPTY
);
3621 sreron
|= SRER_TXDATA
;
3623 sreron
|= SRER_TXEMPTY
;
3625 sreroff
|= SRER_RXDATA
;
3627 sreron
|= SRER_RXDATA
;
3631 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3632 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3633 stl_cd1400setreg(portp
, SRER
,
3634 ((stl_cd1400getreg(portp
, SRER
) & ~sreroff
) | sreron
));
3635 BRDDISABLE(portp
->brdnr
);
3637 set_bit(ASYI_TXBUSY
, &portp
->istate
);
3638 restore_flags(flags
);
3641 /*****************************************************************************/
3644 * Disable all interrupts from this port.
3647 static void stl_cd1400disableintrs(stlport_t
*portp
)
3649 unsigned long flags
;
3652 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp
);
3656 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3657 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3658 stl_cd1400setreg(portp
, SRER
, 0);
3659 BRDDISABLE(portp
->brdnr
);
3660 restore_flags(flags
);
3663 /*****************************************************************************/
3665 static void stl_cd1400sendbreak(stlport_t
*portp
, int len
)
3667 unsigned long flags
;
3670 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
3675 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3676 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3677 stl_cd1400setreg(portp
, SRER
,
3678 ((stl_cd1400getreg(portp
, SRER
) & ~SRER_TXDATA
) |
3680 BRDDISABLE(portp
->brdnr
);
3681 portp
->brklen
= len
;
3683 portp
->stats
.txbreaks
++;
3684 restore_flags(flags
);
3687 /*****************************************************************************/
3690 * Take flow control actions...
3693 static void stl_cd1400flowctrl(stlport_t
*portp
, int state
)
3695 struct tty_struct
*tty
;
3696 unsigned long flags
;
3699 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
3702 if (portp
== (stlport_t
*) NULL
)
3705 if (tty
== (struct tty_struct
*) NULL
)
3710 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3711 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3714 if (tty
->termios
->c_iflag
& IXOFF
) {
3715 stl_cd1400ccrwait(portp
);
3716 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3717 portp
->stats
.rxxon
++;
3718 stl_cd1400ccrwait(portp
);
3721 * Question: should we return RTS to what it was before? It may
3722 * have been set by an ioctl... Suppose not, since if you have
3723 * hardware flow control set then it is pretty silly to go and
3724 * set the RTS line by hand.
3726 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3727 stl_cd1400setreg(portp
, MCOR1
,
3728 (stl_cd1400getreg(portp
, MCOR1
) |
3729 FIFO_RTSTHRESHOLD
));
3730 stl_cd1400setreg(portp
, MSVR2
, MSVR2_RTS
);
3731 portp
->stats
.rxrtson
++;
3734 if (tty
->termios
->c_iflag
& IXOFF
) {
3735 stl_cd1400ccrwait(portp
);
3736 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3737 portp
->stats
.rxxoff
++;
3738 stl_cd1400ccrwait(portp
);
3740 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3741 stl_cd1400setreg(portp
, MCOR1
,
3742 (stl_cd1400getreg(portp
, MCOR1
) & 0xf0));
3743 stl_cd1400setreg(portp
, MSVR2
, 0);
3744 portp
->stats
.rxrtsoff
++;
3748 BRDDISABLE(portp
->brdnr
);
3749 restore_flags(flags
);
3752 /*****************************************************************************/
3755 * Send a flow control character...
3758 static void stl_cd1400sendflow(stlport_t
*portp
, int state
)
3760 struct tty_struct
*tty
;
3761 unsigned long flags
;
3764 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
3767 if (portp
== (stlport_t
*) NULL
)
3770 if (tty
== (struct tty_struct
*) NULL
)
3775 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3776 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3778 stl_cd1400ccrwait(portp
);
3779 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3780 portp
->stats
.rxxon
++;
3781 stl_cd1400ccrwait(portp
);
3783 stl_cd1400ccrwait(portp
);
3784 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3785 portp
->stats
.rxxoff
++;
3786 stl_cd1400ccrwait(portp
);
3788 BRDDISABLE(portp
->brdnr
);
3789 restore_flags(flags
);
3792 /*****************************************************************************/
3794 static void stl_cd1400flush(stlport_t
*portp
)
3796 unsigned long flags
;
3799 printk("stl_cd1400flush(portp=%x)\n", (int) portp
);
3802 if (portp
== (stlport_t
*) NULL
)
3807 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3808 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3809 stl_cd1400ccrwait(portp
);
3810 stl_cd1400setreg(portp
, CCR
, CCR_TXFLUSHFIFO
);
3811 stl_cd1400ccrwait(portp
);
3812 portp
->tx
.tail
= portp
->tx
.head
;
3813 BRDDISABLE(portp
->brdnr
);
3814 restore_flags(flags
);
3817 /*****************************************************************************/
3820 * Return the current state of data flow on this port. This is only
3821 * really interresting when determining if data has fully completed
3822 * transmission or not... This is easy for the cd1400, it accurately
3823 * maintains the busy port flag.
3826 static int stl_cd1400datastate(stlport_t
*portp
)
3829 printk("stl_cd1400datastate(portp=%x)\n", (int) portp
);
3832 if (portp
== (stlport_t
*) NULL
)
3835 return test_bit(ASYI_TXBUSY
, &portp
->istate
) ? 1 : 0;
3838 /*****************************************************************************/
3841 * Interrupt service routine for cd1400 EasyIO boards.
3844 static void stl_cd1400eiointr(stlpanel_t
*panelp
, unsigned int iobase
)
3846 unsigned char svrtype
;
3849 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3850 (int) panelp
, iobase
);
3854 svrtype
= inb(iobase
+ EREG_DATA
);
3855 if (panelp
->nrports
> 4) {
3856 outb((SVRR
+ 0x80), iobase
);
3857 svrtype
|= inb(iobase
+ EREG_DATA
);
3860 if (svrtype
& SVRR_RX
)
3861 stl_cd1400rxisr(panelp
, iobase
);
3862 else if (svrtype
& SVRR_TX
)
3863 stl_cd1400txisr(panelp
, iobase
);
3864 else if (svrtype
& SVRR_MDM
)
3865 stl_cd1400mdmisr(panelp
, iobase
);
3868 /*****************************************************************************/
3871 * Interrupt service routine for cd1400 panels.
3874 static void stl_cd1400echintr(stlpanel_t
*panelp
, unsigned int iobase
)
3876 unsigned char svrtype
;
3879 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp
,
3884 svrtype
= inb(iobase
+ EREG_DATA
);
3885 outb((SVRR
+ 0x80), iobase
);
3886 svrtype
|= inb(iobase
+ EREG_DATA
);
3887 if (svrtype
& SVRR_RX
)
3888 stl_cd1400rxisr(panelp
, iobase
);
3889 else if (svrtype
& SVRR_TX
)
3890 stl_cd1400txisr(panelp
, iobase
);
3891 else if (svrtype
& SVRR_MDM
)
3892 stl_cd1400mdmisr(panelp
, iobase
);
3896 /*****************************************************************************/
3899 * Unfortunately we need to handle breaks in the TX data stream, since
3900 * this is the only way to generate them on the cd1400.
3903 static inline int stl_cd1400breakisr(stlport_t
*portp
, int ioaddr
)
3905 if (portp
->brklen
== 1) {
3906 outb((COR2
+ portp
->uartaddr
), ioaddr
);
3907 outb((inb(ioaddr
+ EREG_DATA
) | COR2_ETC
),
3908 (ioaddr
+ EREG_DATA
));
3909 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3910 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
3911 outb(ETC_STARTBREAK
, (ioaddr
+ EREG_DATA
));
3912 outb((SRER
+ portp
->uartaddr
), ioaddr
);
3913 outb((inb(ioaddr
+ EREG_DATA
) & ~(SRER_TXDATA
| SRER_TXEMPTY
)),
3914 (ioaddr
+ EREG_DATA
));
3916 } else if (portp
->brklen
> 1) {
3917 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3918 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
3919 outb(ETC_STOPBREAK
, (ioaddr
+ EREG_DATA
));
3923 outb((COR2
+ portp
->uartaddr
), ioaddr
);
3924 outb((inb(ioaddr
+ EREG_DATA
) & ~COR2_ETC
),
3925 (ioaddr
+ EREG_DATA
));
3931 /*****************************************************************************/
3934 * Transmit interrupt handler. This has gotta be fast! Handling TX
3935 * chars is pretty simple, stuff as many as possible from the TX buffer
3936 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3937 * are embedded as commands in the data stream. Oh no, had to use a goto!
3938 * This could be optimized more, will do when I get time...
3939 * In practice it is possible that interrupts are enabled but that the
3940 * port has been hung up. Need to handle not having any TX buffer here,
3941 * this is done by using the side effect that head and tail will also
3942 * be NULL if the buffer has been freed.
3945 static void stl_cd1400txisr(stlpanel_t
*panelp
, int ioaddr
)
3950 unsigned char ioack
, srer
;
3953 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
3956 ioack
= inb(ioaddr
+ EREG_TXACK
);
3957 if (((ioack
& panelp
->ackmask
) != 0) ||
3958 ((ioack
& ACK_TYPMASK
) != ACK_TYPTX
)) {
3959 printk("STALLION: bad TX interrupt ack value=%x\n", ioack
);
3962 portp
= panelp
->ports
[(ioack
>> 3)];
3965 * Unfortunately we need to handle breaks in the data stream, since
3966 * this is the only way to generate them on the cd1400. Do it now if
3967 * a break is to be sent.
3969 if (portp
->brklen
!= 0)
3970 if (stl_cd1400breakisr(portp
, ioaddr
))
3973 head
= portp
->tx
.head
;
3974 tail
= portp
->tx
.tail
;
3975 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
3976 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
3977 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
3978 set_bit(ASYI_TXLOW
, &portp
->istate
);
3979 schedule_work(&portp
->tqueue
);
3983 outb((SRER
+ portp
->uartaddr
), ioaddr
);
3984 srer
= inb(ioaddr
+ EREG_DATA
);
3985 if (srer
& SRER_TXDATA
) {
3986 srer
= (srer
& ~SRER_TXDATA
) | SRER_TXEMPTY
;
3988 srer
&= ~(SRER_TXDATA
| SRER_TXEMPTY
);
3989 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
3991 outb(srer
, (ioaddr
+ EREG_DATA
));
3993 len
= MIN(len
, CD1400_TXFIFOSIZE
);
3994 portp
->stats
.txtotal
+= len
;
3995 stlen
= MIN(len
, ((portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
));
3996 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3997 outsb((ioaddr
+ EREG_DATA
), tail
, stlen
);
4000 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
4001 tail
= portp
->tx
.buf
;
4003 outsb((ioaddr
+ EREG_DATA
), tail
, len
);
4006 portp
->tx
.tail
= tail
;
4010 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4011 outb(0, (ioaddr
+ EREG_DATA
));
4014 /*****************************************************************************/
4017 * Receive character interrupt handler. Determine if we have good chars
4018 * or bad chars and then process appropriately. Good chars are easy
4019 * just shove the lot into the RX buffer and set all status byte to 0.
4020 * If a bad RX char then process as required. This routine needs to be
4021 * fast! In practice it is possible that we get an interrupt on a port
4022 * that is closed. This can happen on hangups - since they completely
4023 * shutdown a port not in user context. Need to handle this case.
4026 static void stl_cd1400rxisr(stlpanel_t
*panelp
, int ioaddr
)
4029 struct tty_struct
*tty
;
4030 unsigned int ioack
, len
, buflen
;
4031 unsigned char status
;
4035 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
4038 ioack
= inb(ioaddr
+ EREG_RXACK
);
4039 if ((ioack
& panelp
->ackmask
) != 0) {
4040 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
4043 portp
= panelp
->ports
[(ioack
>> 3)];
4046 if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXGOOD
) {
4047 outb((RDCR
+ portp
->uartaddr
), ioaddr
);
4048 len
= inb(ioaddr
+ EREG_DATA
);
4049 if (tty
== NULL
|| (buflen
= tty_buffer_request_room(tty
, len
)) == 0) {
4050 len
= MIN(len
, sizeof(stl_unwanted
));
4051 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4052 insb((ioaddr
+ EREG_DATA
), &stl_unwanted
[0], len
);
4053 portp
->stats
.rxlost
+= len
;
4054 portp
->stats
.rxtotal
+= len
;
4056 len
= MIN(len
, buflen
);
4059 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4060 tty_prepare_flip_string(tty
, &ptr
, len
);
4061 insb((ioaddr
+ EREG_DATA
), ptr
, len
);
4062 tty_schedule_flip(tty
);
4063 portp
->stats
.rxtotal
+= len
;
4066 } else if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXBAD
) {
4067 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4068 status
= inb(ioaddr
+ EREG_DATA
);
4069 ch
= inb(ioaddr
+ EREG_DATA
);
4070 if (status
& ST_PARITY
)
4071 portp
->stats
.rxparity
++;
4072 if (status
& ST_FRAMING
)
4073 portp
->stats
.rxframing
++;
4074 if (status
& ST_OVERRUN
)
4075 portp
->stats
.rxoverrun
++;
4076 if (status
& ST_BREAK
)
4077 portp
->stats
.rxbreaks
++;
4078 if (status
& ST_SCHARMASK
) {
4079 if ((status
& ST_SCHARMASK
) == ST_SCHAR1
)
4080 portp
->stats
.txxon
++;
4081 if ((status
& ST_SCHARMASK
) == ST_SCHAR2
)
4082 portp
->stats
.txxoff
++;
4085 if (tty
!= NULL
&& (portp
->rxignoremsk
& status
) == 0) {
4086 if (portp
->rxmarkmsk
& status
) {
4087 if (status
& ST_BREAK
) {
4089 if (portp
->flags
& ASYNC_SAK
) {
4091 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4093 } else if (status
& ST_PARITY
) {
4094 status
= TTY_PARITY
;
4095 } else if (status
& ST_FRAMING
) {
4097 } else if(status
& ST_OVERRUN
) {
4098 status
= TTY_OVERRUN
;
4105 tty_insert_flip_char(tty
, ch
, status
);
4106 tty_schedule_flip(tty
);
4109 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
4114 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4115 outb(0, (ioaddr
+ EREG_DATA
));
4118 /*****************************************************************************/
4121 * Modem interrupt handler. The is called when the modem signal line
4122 * (DCD) has changed state. Leave most of the work to the off-level
4123 * processing routine.
4126 static void stl_cd1400mdmisr(stlpanel_t
*panelp
, int ioaddr
)
4133 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp
);
4136 ioack
= inb(ioaddr
+ EREG_MDACK
);
4137 if (((ioack
& panelp
->ackmask
) != 0) ||
4138 ((ioack
& ACK_TYPMASK
) != ACK_TYPMDM
)) {
4139 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack
);
4142 portp
= panelp
->ports
[(ioack
>> 3)];
4144 outb((MISR
+ portp
->uartaddr
), ioaddr
);
4145 misr
= inb(ioaddr
+ EREG_DATA
);
4146 if (misr
& MISR_DCD
) {
4147 set_bit(ASYI_DCDCHANGE
, &portp
->istate
);
4148 schedule_work(&portp
->tqueue
);
4149 portp
->stats
.modem
++;
4152 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4153 outb(0, (ioaddr
+ EREG_DATA
));
4156 /*****************************************************************************/
4157 /* SC26198 HARDWARE FUNCTIONS */
4158 /*****************************************************************************/
4161 * These functions get/set/update the registers of the sc26198 UARTs.
4162 * Access to the sc26198 registers is via an address/data io port pair.
4163 * (Maybe should make this inline...)
4166 static int stl_sc26198getreg(stlport_t
*portp
, int regnr
)
4168 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4169 return inb(portp
->ioaddr
+ XP_DATA
);
4172 static void stl_sc26198setreg(stlport_t
*portp
, int regnr
, int value
)
4174 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4175 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4178 static int stl_sc26198updatereg(stlport_t
*portp
, int regnr
, int value
)
4180 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4181 if (inb(portp
->ioaddr
+ XP_DATA
) != value
) {
4182 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4188 /*****************************************************************************/
4191 * Functions to get and set the sc26198 global registers.
4194 static int stl_sc26198getglobreg(stlport_t
*portp
, int regnr
)
4196 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
4197 return inb(portp
->ioaddr
+ XP_DATA
);
4201 static void stl_sc26198setglobreg(stlport_t
*portp
, int regnr
, int value
)
4203 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
4204 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4208 /*****************************************************************************/
4211 * Inbitialize the UARTs in a panel. We don't care what sort of board
4212 * these ports are on - since the port io registers are almost
4213 * identical when dealing with ports.
4216 static int stl_sc26198panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
4219 int nrchips
, ioaddr
;
4222 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4223 (int) brdp
, (int) panelp
);
4226 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
4229 * Check that each chip is present and started up OK.
4232 nrchips
= (panelp
->nrports
+ 4) / SC26198_PORTS
;
4233 if (brdp
->brdtype
== BRD_ECHPCI
)
4234 outb(panelp
->pagenr
, brdp
->ioctrl
);
4236 for (i
= 0; (i
< nrchips
); i
++) {
4237 ioaddr
= panelp
->iobase
+ (i
* 4);
4238 outb(SCCR
, (ioaddr
+ XP_ADDR
));
4239 outb(CR_RESETALL
, (ioaddr
+ XP_DATA
));
4240 outb(TSTR
, (ioaddr
+ XP_ADDR
));
4241 if (inb(ioaddr
+ XP_DATA
) != 0) {
4242 printk("STALLION: sc26198 not responding, "
4243 "brd=%d panel=%d chip=%d\n",
4244 panelp
->brdnr
, panelp
->panelnr
, i
);
4247 chipmask
|= (0x1 << i
);
4248 outb(GCCR
, (ioaddr
+ XP_ADDR
));
4249 outb(GCCR_IVRTYPCHANACK
, (ioaddr
+ XP_DATA
));
4250 outb(WDTRCR
, (ioaddr
+ XP_ADDR
));
4251 outb(0xff, (ioaddr
+ XP_DATA
));
4254 BRDDISABLE(panelp
->brdnr
);
4258 /*****************************************************************************/
4261 * Initialize hardware specific port registers.
4264 static void stl_sc26198portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
4267 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4268 (int) brdp
, (int) panelp
, (int) portp
);
4271 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
4272 (portp
== (stlport_t
*) NULL
))
4275 portp
->ioaddr
= panelp
->iobase
+ ((portp
->portnr
< 8) ? 0 : 4);
4276 portp
->uartaddr
= (portp
->portnr
& 0x07) << 4;
4277 portp
->pagenr
= panelp
->pagenr
;
4280 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4281 stl_sc26198setreg(portp
, IOPCR
, IOPCR_SETSIGS
);
4282 BRDDISABLE(portp
->brdnr
);
4285 /*****************************************************************************/
4288 * Set up the sc26198 registers for a port based on the termios port
4292 static void stl_sc26198setport(stlport_t
*portp
, struct termios
*tiosp
)
4295 unsigned long flags
;
4296 unsigned int baudrate
;
4297 unsigned char mr0
, mr1
, mr2
, clk
;
4298 unsigned char imron
, imroff
, iopr
, ipr
;
4308 brdp
= stl_brds
[portp
->brdnr
];
4309 if (brdp
== (stlbrd_t
*) NULL
)
4313 * Set up the RX char ignore mask with those RX error types we
4316 portp
->rxignoremsk
= 0;
4317 if (tiosp
->c_iflag
& IGNPAR
)
4318 portp
->rxignoremsk
|= (SR_RXPARITY
| SR_RXFRAMING
|
4320 if (tiosp
->c_iflag
& IGNBRK
)
4321 portp
->rxignoremsk
|= SR_RXBREAK
;
4323 portp
->rxmarkmsk
= SR_RXOVERRUN
;
4324 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
4325 portp
->rxmarkmsk
|= (SR_RXPARITY
| SR_RXFRAMING
);
4326 if (tiosp
->c_iflag
& BRKINT
)
4327 portp
->rxmarkmsk
|= SR_RXBREAK
;
4330 * Go through the char size, parity and stop bits and set all the
4331 * option register appropriately.
4333 switch (tiosp
->c_cflag
& CSIZE
) {
4348 if (tiosp
->c_cflag
& CSTOPB
)
4353 if (tiosp
->c_cflag
& PARENB
) {
4354 if (tiosp
->c_cflag
& PARODD
)
4355 mr1
|= (MR1_PARENB
| MR1_PARODD
);
4357 mr1
|= (MR1_PARENB
| MR1_PAREVEN
);
4362 mr1
|= MR1_ERRBLOCK
;
4365 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4366 * space for hardware flow control and the like. This should be set to
4369 mr2
|= MR2_RXFIFOHALF
;
4372 * Calculate the baud rate timers. For now we will just assume that
4373 * the input and output baud are the same. The sc26198 has a fixed
4374 * baud rate table, so only discrete baud rates possible.
4376 baudrate
= tiosp
->c_cflag
& CBAUD
;
4377 if (baudrate
& CBAUDEX
) {
4378 baudrate
&= ~CBAUDEX
;
4379 if ((baudrate
< 1) || (baudrate
> 4))
4380 tiosp
->c_cflag
&= ~CBAUDEX
;
4384 baudrate
= stl_baudrates
[baudrate
];
4385 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
4386 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
4388 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
4390 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
4392 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
4394 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
4395 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
4397 if (baudrate
> STL_SC26198MAXBAUD
)
4398 baudrate
= STL_SC26198MAXBAUD
;
4401 for (clk
= 0; (clk
< SC26198_NRBAUDS
); clk
++) {
4402 if (baudrate
<= sc26198_baudtable
[clk
])
4408 * Check what form of modem signaling is required and set it up.
4410 if (tiosp
->c_cflag
& CLOCAL
) {
4411 portp
->flags
&= ~ASYNC_CHECK_CD
;
4413 iopr
|= IOPR_DCDCOS
;
4415 portp
->flags
|= ASYNC_CHECK_CD
;
4419 * Setup sc26198 enhanced modes if we can. In particular we want to
4420 * handle as much of the flow control as possible automatically. As
4421 * well as saving a few CPU cycles it will also greatly improve flow
4422 * control reliability.
4424 if (tiosp
->c_iflag
& IXON
) {
4425 mr0
|= MR0_SWFTX
| MR0_SWFT
;
4426 imron
|= IR_XONXOFF
;
4428 imroff
|= IR_XONXOFF
;
4430 if (tiosp
->c_iflag
& IXOFF
)
4433 if (tiosp
->c_cflag
& CRTSCTS
) {
4439 * All sc26198 register values calculated so go through and set
4444 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4445 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
4446 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0
, mr1
, mr2
, clk
);
4447 printk(" iopr=%x imron=%x imroff=%x\n", iopr
, imron
, imroff
);
4448 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4449 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
4450 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
4455 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4456 stl_sc26198setreg(portp
, IMR
, 0);
4457 stl_sc26198updatereg(portp
, MR0
, mr0
);
4458 stl_sc26198updatereg(portp
, MR1
, mr1
);
4459 stl_sc26198setreg(portp
, SCCR
, CR_RXERRBLOCK
);
4460 stl_sc26198updatereg(portp
, MR2
, mr2
);
4461 stl_sc26198updatereg(portp
, IOPIOR
,
4462 ((stl_sc26198getreg(portp
, IOPIOR
) & ~IPR_CHANGEMASK
) | iopr
));
4465 stl_sc26198setreg(portp
, TXCSR
, clk
);
4466 stl_sc26198setreg(portp
, RXCSR
, clk
);
4469 stl_sc26198setreg(portp
, XONCR
, tiosp
->c_cc
[VSTART
]);
4470 stl_sc26198setreg(portp
, XOFFCR
, tiosp
->c_cc
[VSTOP
]);
4472 ipr
= stl_sc26198getreg(portp
, IPR
);
4474 portp
->sigs
&= ~TIOCM_CD
;
4476 portp
->sigs
|= TIOCM_CD
;
4478 portp
->imr
= (portp
->imr
& ~imroff
) | imron
;
4479 stl_sc26198setreg(portp
, IMR
, portp
->imr
);
4480 BRDDISABLE(portp
->brdnr
);
4481 restore_flags(flags
);
4484 /*****************************************************************************/
4487 * Set the state of the DTR and RTS signals.
4490 static void stl_sc26198setsignals(stlport_t
*portp
, int dtr
, int rts
)
4492 unsigned char iopioron
, iopioroff
;
4493 unsigned long flags
;
4496 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4497 (int) portp
, dtr
, rts
);
4503 iopioroff
|= IPR_DTR
;
4505 iopioron
|= IPR_DTR
;
4507 iopioroff
|= IPR_RTS
;
4509 iopioron
|= IPR_RTS
;
4513 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4514 stl_sc26198setreg(portp
, IOPIOR
,
4515 ((stl_sc26198getreg(portp
, IOPIOR
) & ~iopioroff
) | iopioron
));
4516 BRDDISABLE(portp
->brdnr
);
4517 restore_flags(flags
);
4520 /*****************************************************************************/
4523 * Return the state of the signals.
4526 static int stl_sc26198getsignals(stlport_t
*portp
)
4529 unsigned long flags
;
4533 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp
);
4538 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4539 ipr
= stl_sc26198getreg(portp
, IPR
);
4540 BRDDISABLE(portp
->brdnr
);
4541 restore_flags(flags
);
4544 sigs
|= (ipr
& IPR_DCD
) ? 0 : TIOCM_CD
;
4545 sigs
|= (ipr
& IPR_CTS
) ? 0 : TIOCM_CTS
;
4546 sigs
|= (ipr
& IPR_DTR
) ? 0: TIOCM_DTR
;
4547 sigs
|= (ipr
& IPR_RTS
) ? 0: TIOCM_RTS
;
4552 /*****************************************************************************/
4555 * Enable/Disable the Transmitter and/or Receiver.
4558 static void stl_sc26198enablerxtx(stlport_t
*portp
, int rx
, int tx
)
4561 unsigned long flags
;
4564 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4565 (int) portp
, rx
, tx
);
4568 ccr
= portp
->crenable
;
4570 ccr
&= ~CR_TXENABLE
;
4574 ccr
&= ~CR_RXENABLE
;
4580 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4581 stl_sc26198setreg(portp
, SCCR
, ccr
);
4582 BRDDISABLE(portp
->brdnr
);
4583 portp
->crenable
= ccr
;
4584 restore_flags(flags
);
4587 /*****************************************************************************/
4590 * Start/stop the Transmitter and/or Receiver.
4593 static void stl_sc26198startrxtx(stlport_t
*portp
, int rx
, int tx
)
4596 unsigned long flags
;
4599 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4600 (int) portp
, rx
, tx
);
4609 imr
&= ~(IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
);
4611 imr
|= IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
;
4615 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4616 stl_sc26198setreg(portp
, IMR
, imr
);
4617 BRDDISABLE(portp
->brdnr
);
4620 set_bit(ASYI_TXBUSY
, &portp
->istate
);
4621 restore_flags(flags
);
4624 /*****************************************************************************/
4627 * Disable all interrupts from this port.
4630 static void stl_sc26198disableintrs(stlport_t
*portp
)
4632 unsigned long flags
;
4635 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp
);
4640 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4642 stl_sc26198setreg(portp
, IMR
, 0);
4643 BRDDISABLE(portp
->brdnr
);
4644 restore_flags(flags
);
4647 /*****************************************************************************/
4649 static void stl_sc26198sendbreak(stlport_t
*portp
, int len
)
4651 unsigned long flags
;
4654 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
4659 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4661 stl_sc26198setreg(portp
, SCCR
, CR_TXSTARTBREAK
);
4662 portp
->stats
.txbreaks
++;
4664 stl_sc26198setreg(portp
, SCCR
, CR_TXSTOPBREAK
);
4666 BRDDISABLE(portp
->brdnr
);
4667 restore_flags(flags
);
4670 /*****************************************************************************/
4673 * Take flow control actions...
4676 static void stl_sc26198flowctrl(stlport_t
*portp
, int state
)
4678 struct tty_struct
*tty
;
4679 unsigned long flags
;
4683 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
4686 if (portp
== (stlport_t
*) NULL
)
4689 if (tty
== (struct tty_struct
*) NULL
)
4694 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4697 if (tty
->termios
->c_iflag
& IXOFF
) {
4698 mr0
= stl_sc26198getreg(portp
, MR0
);
4699 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4700 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4702 portp
->stats
.rxxon
++;
4703 stl_sc26198wait(portp
);
4704 stl_sc26198setreg(portp
, MR0
, mr0
);
4707 * Question: should we return RTS to what it was before? It may
4708 * have been set by an ioctl... Suppose not, since if you have
4709 * hardware flow control set then it is pretty silly to go and
4710 * set the RTS line by hand.
4712 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4713 stl_sc26198setreg(portp
, MR1
,
4714 (stl_sc26198getreg(portp
, MR1
) | MR1_AUTORTS
));
4715 stl_sc26198setreg(portp
, IOPIOR
,
4716 (stl_sc26198getreg(portp
, IOPIOR
) | IOPR_RTS
));
4717 portp
->stats
.rxrtson
++;
4720 if (tty
->termios
->c_iflag
& IXOFF
) {
4721 mr0
= stl_sc26198getreg(portp
, MR0
);
4722 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4723 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4725 portp
->stats
.rxxoff
++;
4726 stl_sc26198wait(portp
);
4727 stl_sc26198setreg(portp
, MR0
, mr0
);
4729 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4730 stl_sc26198setreg(portp
, MR1
,
4731 (stl_sc26198getreg(portp
, MR1
) & ~MR1_AUTORTS
));
4732 stl_sc26198setreg(portp
, IOPIOR
,
4733 (stl_sc26198getreg(portp
, IOPIOR
) & ~IOPR_RTS
));
4734 portp
->stats
.rxrtsoff
++;
4738 BRDDISABLE(portp
->brdnr
);
4739 restore_flags(flags
);
4742 /*****************************************************************************/
4745 * Send a flow control character.
4748 static void stl_sc26198sendflow(stlport_t
*portp
, int state
)
4750 struct tty_struct
*tty
;
4751 unsigned long flags
;
4755 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
4758 if (portp
== (stlport_t
*) NULL
)
4761 if (tty
== (struct tty_struct
*) NULL
)
4766 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4768 mr0
= stl_sc26198getreg(portp
, MR0
);
4769 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4770 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4772 portp
->stats
.rxxon
++;
4773 stl_sc26198wait(portp
);
4774 stl_sc26198setreg(portp
, MR0
, mr0
);
4776 mr0
= stl_sc26198getreg(portp
, MR0
);
4777 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4778 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4780 portp
->stats
.rxxoff
++;
4781 stl_sc26198wait(portp
);
4782 stl_sc26198setreg(portp
, MR0
, mr0
);
4784 BRDDISABLE(portp
->brdnr
);
4785 restore_flags(flags
);
4788 /*****************************************************************************/
4790 static void stl_sc26198flush(stlport_t
*portp
)
4792 unsigned long flags
;
4795 printk("stl_sc26198flush(portp=%x)\n", (int) portp
);
4798 if (portp
== (stlport_t
*) NULL
)
4803 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4804 stl_sc26198setreg(portp
, SCCR
, CR_TXRESET
);
4805 stl_sc26198setreg(portp
, SCCR
, portp
->crenable
);
4806 BRDDISABLE(portp
->brdnr
);
4807 portp
->tx
.tail
= portp
->tx
.head
;
4808 restore_flags(flags
);
4811 /*****************************************************************************/
4814 * Return the current state of data flow on this port. This is only
4815 * really interresting when determining if data has fully completed
4816 * transmission or not... The sc26198 interrupt scheme cannot
4817 * determine when all data has actually drained, so we need to
4818 * check the port statusy register to be sure.
4821 static int stl_sc26198datastate(stlport_t
*portp
)
4823 unsigned long flags
;
4827 printk("stl_sc26198datastate(portp=%x)\n", (int) portp
);
4830 if (portp
== (stlport_t
*) NULL
)
4832 if (test_bit(ASYI_TXBUSY
, &portp
->istate
))
4837 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4838 sr
= stl_sc26198getreg(portp
, SR
);
4839 BRDDISABLE(portp
->brdnr
);
4840 restore_flags(flags
);
4842 return (sr
& SR_TXEMPTY
) ? 0 : 1;
4845 /*****************************************************************************/
4848 * Delay for a small amount of time, to give the sc26198 a chance
4849 * to process a command...
4852 static void stl_sc26198wait(stlport_t
*portp
)
4857 printk("stl_sc26198wait(portp=%x)\n", (int) portp
);
4860 if (portp
== (stlport_t
*) NULL
)
4863 for (i
= 0; (i
< 20); i
++)
4864 stl_sc26198getglobreg(portp
, TSTR
);
4867 /*****************************************************************************/
4870 * If we are TX flow controlled and in IXANY mode then we may
4871 * need to unflow control here. We gotta do this because of the
4872 * automatic flow control modes of the sc26198.
4875 static inline void stl_sc26198txunflow(stlport_t
*portp
, struct tty_struct
*tty
)
4879 mr0
= stl_sc26198getreg(portp
, MR0
);
4880 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4881 stl_sc26198setreg(portp
, SCCR
, CR_HOSTXON
);
4882 stl_sc26198wait(portp
);
4883 stl_sc26198setreg(portp
, MR0
, mr0
);
4884 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
4887 /*****************************************************************************/
4890 * Interrupt service routine for sc26198 panels.
4893 static void stl_sc26198intr(stlpanel_t
*panelp
, unsigned int iobase
)
4899 * Work around bug in sc26198 chip... Cannot have A6 address
4900 * line of UART high, else iack will be returned as 0.
4902 outb(0, (iobase
+ 1));
4904 iack
= inb(iobase
+ XP_IACK
);
4905 portp
= panelp
->ports
[(iack
& IVR_CHANMASK
) + ((iobase
& 0x4) << 1)];
4907 if (iack
& IVR_RXDATA
)
4908 stl_sc26198rxisr(portp
, iack
);
4909 else if (iack
& IVR_TXDATA
)
4910 stl_sc26198txisr(portp
);
4912 stl_sc26198otherisr(portp
, iack
);
4915 /*****************************************************************************/
4918 * Transmit interrupt handler. This has gotta be fast! Handling TX
4919 * chars is pretty simple, stuff as many as possible from the TX buffer
4920 * into the sc26198 FIFO.
4921 * In practice it is possible that interrupts are enabled but that the
4922 * port has been hung up. Need to handle not having any TX buffer here,
4923 * this is done by using the side effect that head and tail will also
4924 * be NULL if the buffer has been freed.
4927 static void stl_sc26198txisr(stlport_t
*portp
)
4929 unsigned int ioaddr
;
4935 printk("stl_sc26198txisr(portp=%x)\n", (int) portp
);
4938 ioaddr
= portp
->ioaddr
;
4939 head
= portp
->tx
.head
;
4940 tail
= portp
->tx
.tail
;
4941 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
4942 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
4943 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
4944 set_bit(ASYI_TXLOW
, &portp
->istate
);
4945 schedule_work(&portp
->tqueue
);
4949 outb((MR0
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
4950 mr0
= inb(ioaddr
+ XP_DATA
);
4951 if ((mr0
& MR0_TXMASK
) == MR0_TXEMPTY
) {
4952 portp
->imr
&= ~IR_TXRDY
;
4953 outb((IMR
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
4954 outb(portp
->imr
, (ioaddr
+ XP_DATA
));
4955 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
4957 mr0
|= ((mr0
& ~MR0_TXMASK
) | MR0_TXEMPTY
);
4958 outb(mr0
, (ioaddr
+ XP_DATA
));
4961 len
= MIN(len
, SC26198_TXFIFOSIZE
);
4962 portp
->stats
.txtotal
+= len
;
4963 stlen
= MIN(len
, ((portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
));
4964 outb(GTXFIFO
, (ioaddr
+ XP_ADDR
));
4965 outsb((ioaddr
+ XP_DATA
), tail
, stlen
);
4968 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
4969 tail
= portp
->tx
.buf
;
4971 outsb((ioaddr
+ XP_DATA
), tail
, len
);
4974 portp
->tx
.tail
= tail
;
4978 /*****************************************************************************/
4981 * Receive character interrupt handler. Determine if we have good chars
4982 * or bad chars and then process appropriately. Good chars are easy
4983 * just shove the lot into the RX buffer and set all status byte to 0.
4984 * If a bad RX char then process as required. This routine needs to be
4985 * fast! In practice it is possible that we get an interrupt on a port
4986 * that is closed. This can happen on hangups - since they completely
4987 * shutdown a port not in user context. Need to handle this case.
4990 static void stl_sc26198rxisr(stlport_t
*portp
, unsigned int iack
)
4992 struct tty_struct
*tty
;
4993 unsigned int len
, buflen
, ioaddr
;
4996 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
5000 ioaddr
= portp
->ioaddr
;
5001 outb(GIBCR
, (ioaddr
+ XP_ADDR
));
5002 len
= inb(ioaddr
+ XP_DATA
) + 1;
5004 if ((iack
& IVR_TYPEMASK
) == IVR_RXDATA
) {
5005 if (tty
== NULL
|| (buflen
= tty_buffer_request_room(tty
, len
)) == 0) {
5006 len
= MIN(len
, sizeof(stl_unwanted
));
5007 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
5008 insb((ioaddr
+ XP_DATA
), &stl_unwanted
[0], len
);
5009 portp
->stats
.rxlost
+= len
;
5010 portp
->stats
.rxtotal
+= len
;
5012 len
= MIN(len
, buflen
);
5015 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
5016 tty_prepare_flip_string(tty
, &ptr
, len
);
5017 insb((ioaddr
+ XP_DATA
), ptr
, len
);
5018 tty_schedule_flip(tty
);
5019 portp
->stats
.rxtotal
+= len
;
5023 stl_sc26198rxbadchars(portp
);
5027 * If we are TX flow controlled and in IXANY mode then we may need
5028 * to unflow control here. We gotta do this because of the automatic
5029 * flow control modes of the sc26198.
5031 if (test_bit(ASYI_TXFLOWED
, &portp
->istate
)) {
5032 if ((tty
!= (struct tty_struct
*) NULL
) &&
5033 (tty
->termios
!= (struct termios
*) NULL
) &&
5034 (tty
->termios
->c_iflag
& IXANY
)) {
5035 stl_sc26198txunflow(portp
, tty
);
5040 /*****************************************************************************/
5043 * Process an RX bad character.
5046 static inline void stl_sc26198rxbadch(stlport_t
*portp
, unsigned char status
, char ch
)
5048 struct tty_struct
*tty
;
5049 unsigned int ioaddr
;
5052 ioaddr
= portp
->ioaddr
;
5054 if (status
& SR_RXPARITY
)
5055 portp
->stats
.rxparity
++;
5056 if (status
& SR_RXFRAMING
)
5057 portp
->stats
.rxframing
++;
5058 if (status
& SR_RXOVERRUN
)
5059 portp
->stats
.rxoverrun
++;
5060 if (status
& SR_RXBREAK
)
5061 portp
->stats
.rxbreaks
++;
5063 if ((tty
!= (struct tty_struct
*) NULL
) &&
5064 ((portp
->rxignoremsk
& status
) == 0)) {
5065 if (portp
->rxmarkmsk
& status
) {
5066 if (status
& SR_RXBREAK
) {
5068 if (portp
->flags
& ASYNC_SAK
) {
5070 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
5072 } else if (status
& SR_RXPARITY
) {
5073 status
= TTY_PARITY
;
5074 } else if (status
& SR_RXFRAMING
) {
5076 } else if(status
& SR_RXOVERRUN
) {
5077 status
= TTY_OVERRUN
;
5085 tty_insert_flip_char(tty
, ch
, status
);
5086 tty_schedule_flip(tty
);
5089 portp
->stats
.rxtotal
++;
5093 /*****************************************************************************/
5096 * Process all characters in the RX FIFO of the UART. Check all char
5097 * status bytes as well, and process as required. We need to check
5098 * all bytes in the FIFO, in case some more enter the FIFO while we
5099 * are here. To get the exact character error type we need to switch
5100 * into CHAR error mode (that is why we need to make sure we empty
5104 static void stl_sc26198rxbadchars(stlport_t
*portp
)
5106 unsigned char status
, mr1
;
5110 * To get the precise error type for each character we must switch
5111 * back into CHAR error mode.
5113 mr1
= stl_sc26198getreg(portp
, MR1
);
5114 stl_sc26198setreg(portp
, MR1
, (mr1
& ~MR1_ERRBLOCK
));
5116 while ((status
= stl_sc26198getreg(portp
, SR
)) & SR_RXRDY
) {
5117 stl_sc26198setreg(portp
, SCCR
, CR_CLEARRXERR
);
5118 ch
= stl_sc26198getreg(portp
, RXFIFO
);
5119 stl_sc26198rxbadch(portp
, status
, ch
);
5123 * To get correct interrupt class we must switch back into BLOCK
5126 stl_sc26198setreg(portp
, MR1
, mr1
);
5129 /*****************************************************************************/
5132 * Other interrupt handler. This includes modem signals, flow
5133 * control actions, etc. Most stuff is left to off-level interrupt
5137 static void stl_sc26198otherisr(stlport_t
*portp
, unsigned int iack
)
5139 unsigned char cir
, ipr
, xisr
;
5142 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
5145 cir
= stl_sc26198getglobreg(portp
, CIR
);
5147 switch (cir
& CIR_SUBTYPEMASK
) {
5149 ipr
= stl_sc26198getreg(portp
, IPR
);
5150 if (ipr
& IPR_DCDCHANGE
) {
5151 set_bit(ASYI_DCDCHANGE
, &portp
->istate
);
5152 schedule_work(&portp
->tqueue
);
5153 portp
->stats
.modem
++;
5156 case CIR_SUBXONXOFF
:
5157 xisr
= stl_sc26198getreg(portp
, XISR
);
5158 if (xisr
& XISR_RXXONGOT
) {
5159 set_bit(ASYI_TXFLOWED
, &portp
->istate
);
5160 portp
->stats
.txxoff
++;
5162 if (xisr
& XISR_RXXOFFGOT
) {
5163 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
5164 portp
->stats
.txxon
++;
5168 stl_sc26198setreg(portp
, SCCR
, CR_BREAKRESET
);
5169 stl_sc26198rxbadchars(portp
);
5176 /*****************************************************************************/