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
;
153 * Define a local default termios struct. All ports will be created
154 * with this termios initially. Basically all it defines is a raw port
155 * at 9600, 8 data bits, 1 stop bit.
157 static struct termios stl_deftermios
= {
158 .c_cflag
= (B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
),
163 * Define global stats structures. Not used often, and can be
164 * re-used for each stats call.
166 static comstats_t stl_comstats
;
167 static combrd_t stl_brdstats
;
168 static stlbrd_t stl_dummybrd
;
169 static stlport_t stl_dummyport
;
172 * Define global place to put buffer overflow characters.
174 static char stl_unwanted
[SC26198_RXFIFOSIZE
];
176 /*****************************************************************************/
178 static stlbrd_t
*stl_brds
[STL_MAXBRDS
];
181 * Per board state flags. Used with the state field of the board struct.
182 * Not really much here!
184 #define BRD_FOUND 0x1
187 * Define the port structure istate flags. These set of flags are
188 * modified at interrupt time - so setting and reseting them needs
189 * to be atomic. Use the bit clear/setting routines for this.
191 #define ASYI_TXBUSY 1
193 #define ASYI_DCDCHANGE 3
194 #define ASYI_TXFLOWED 4
197 * Define an array of board names as printable strings. Handy for
198 * referencing boards when printing trace and stuff.
200 static char *stl_brdnames
[] = {
232 /*****************************************************************************/
235 * Define some string labels for arguments passed from the module
236 * load line. These allow for easy board definitions, and easy
237 * modification of the io, memory and irq resoucres.
239 static int stl_nargs
= 0;
240 static char *board0
[4];
241 static char *board1
[4];
242 static char *board2
[4];
243 static char *board3
[4];
245 static char **stl_brdsp
[] = {
253 * Define a set of common board names, and types. This is used to
254 * parse any module arguments.
257 typedef struct stlbrdtype
{
262 static stlbrdtype_t stl_brdstr
[] = {
263 { "easyio", BRD_EASYIO
},
264 { "eio", BRD_EASYIO
},
265 { "20", BRD_EASYIO
},
266 { "ec8/32", BRD_ECH
},
267 { "ec8/32-at", BRD_ECH
},
268 { "ec8/32-isa", BRD_ECH
},
270 { "echat", BRD_ECH
},
272 { "ec8/32-mc", BRD_ECHMC
},
273 { "ec8/32-mca", BRD_ECHMC
},
274 { "echmc", BRD_ECHMC
},
275 { "echmca", BRD_ECHMC
},
277 { "ec8/32-pc", BRD_ECHPCI
},
278 { "ec8/32-pci", BRD_ECHPCI
},
279 { "26", BRD_ECHPCI
},
280 { "ec8/64-pc", BRD_ECH64PCI
},
281 { "ec8/64-pci", BRD_ECH64PCI
},
282 { "ech-pci", BRD_ECH64PCI
},
283 { "echpci", BRD_ECH64PCI
},
284 { "echpc", BRD_ECH64PCI
},
285 { "27", BRD_ECH64PCI
},
286 { "easyio-pc", BRD_EASYIOPCI
},
287 { "easyio-pci", BRD_EASYIOPCI
},
288 { "eio-pci", BRD_EASYIOPCI
},
289 { "eiopci", BRD_EASYIOPCI
},
290 { "28", BRD_EASYIOPCI
},
294 * Define the module agruments.
296 MODULE_AUTHOR("Greg Ungerer");
297 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
298 MODULE_LICENSE("GPL");
300 module_param_array(board0
, charp
, &stl_nargs
, 0);
301 MODULE_PARM_DESC(board0
, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
302 module_param_array(board1
, charp
, &stl_nargs
, 0);
303 MODULE_PARM_DESC(board1
, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
304 module_param_array(board2
, charp
, &stl_nargs
, 0);
305 MODULE_PARM_DESC(board2
, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
306 module_param_array(board3
, charp
, &stl_nargs
, 0);
307 MODULE_PARM_DESC(board3
, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
309 /*****************************************************************************/
312 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
313 * to the directly accessible io ports of these boards (not the uarts -
314 * they are in cd1400.h and sc26198.h).
316 #define EIO_8PORTRS 0x04
317 #define EIO_4PORTRS 0x05
318 #define EIO_8PORTDI 0x00
319 #define EIO_8PORTM 0x06
321 #define EIO_IDBITMASK 0x07
323 #define EIO_BRDMASK 0xf0
326 #define ID_BRD16 0x30
328 #define EIO_INTRPEND 0x08
329 #define EIO_INTEDGE 0x00
330 #define EIO_INTLEVEL 0x08
334 #define ECH_IDBITMASK 0xe0
335 #define ECH_BRDENABLE 0x08
336 #define ECH_BRDDISABLE 0x00
337 #define ECH_INTENABLE 0x01
338 #define ECH_INTDISABLE 0x00
339 #define ECH_INTLEVEL 0x02
340 #define ECH_INTEDGE 0x00
341 #define ECH_INTRPEND 0x01
342 #define ECH_BRDRESET 0x01
344 #define ECHMC_INTENABLE 0x01
345 #define ECHMC_BRDRESET 0x02
347 #define ECH_PNLSTATUS 2
348 #define ECH_PNL16PORT 0x20
349 #define ECH_PNLIDMASK 0x07
350 #define ECH_PNLXPID 0x40
351 #define ECH_PNLINTRPEND 0x80
353 #define ECH_ADDR2MASK 0x1e0
356 * Define the vector mapping bits for the programmable interrupt board
357 * hardware. These bits encode the interrupt for the board to use - it
358 * is software selectable (except the EIO-8M).
360 static unsigned char stl_vecmap
[] = {
361 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
362 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
366 * Set up enable and disable macros for the ECH boards. They require
367 * the secondary io address space to be activated and deactivated.
368 * This way all ECH boards can share their secondary io region.
369 * If this is an ECH-PCI board then also need to set the page pointer
370 * to point to the correct page.
372 #define BRDENABLE(brdnr,pagenr) \
373 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
374 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
375 stl_brds[(brdnr)]->ioctrl); \
376 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
377 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
379 #define BRDDISABLE(brdnr) \
380 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
381 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
382 stl_brds[(brdnr)]->ioctrl);
384 #define STL_CD1400MAXBAUD 230400
385 #define STL_SC26198MAXBAUD 460800
387 #define STL_BAUDBASE 115200
388 #define STL_CLOSEDELAY (5 * HZ / 10)
390 /*****************************************************************************/
395 * Define the Stallion PCI vendor and device IDs.
397 #ifndef PCI_VENDOR_ID_STALLION
398 #define PCI_VENDOR_ID_STALLION 0x124d
400 #ifndef PCI_DEVICE_ID_ECHPCI832
401 #define PCI_DEVICE_ID_ECHPCI832 0x0000
403 #ifndef PCI_DEVICE_ID_ECHPCI864
404 #define PCI_DEVICE_ID_ECHPCI864 0x0002
406 #ifndef PCI_DEVICE_ID_EIOPCI
407 #define PCI_DEVICE_ID_EIOPCI 0x0003
411 * Define structure to hold all Stallion PCI boards.
413 typedef struct stlpcibrd
{
414 unsigned short vendid
;
415 unsigned short devid
;
419 static stlpcibrd_t stl_pcibrds
[] = {
420 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI864
, BRD_ECH64PCI
},
421 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_EIOPCI
, BRD_EASYIOPCI
},
422 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI832
, BRD_ECHPCI
},
423 { PCI_VENDOR_ID_NS
, PCI_DEVICE_ID_NS_87410
, BRD_ECHPCI
},
426 static int stl_nrpcibrds
= ARRAY_SIZE(stl_pcibrds
);
430 /*****************************************************************************/
433 * Define macros to extract a brd/port number from a minor number.
435 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
436 #define MINOR2PORT(min) ((min) & 0x3f)
439 * Define a baud rate table that converts termios baud rate selector
440 * into the actual baud rate value. All baud rate calculations are
441 * based on the actual baud rate required.
443 static unsigned int stl_baudrates
[] = {
444 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
445 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
449 * Define some handy local macros...
452 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
455 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
457 /*****************************************************************************/
460 * Declare all those functions in this driver!
463 static void stl_argbrds(void);
464 static int stl_parsebrd(stlconf_t
*confp
, char **argp
);
466 static unsigned long stl_atol(char *str
);
468 static int stl_init(void);
469 static int stl_open(struct tty_struct
*tty
, struct file
*filp
);
470 static void stl_close(struct tty_struct
*tty
, struct file
*filp
);
471 static int stl_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
);
472 static void stl_putchar(struct tty_struct
*tty
, unsigned char ch
);
473 static void stl_flushchars(struct tty_struct
*tty
);
474 static int stl_writeroom(struct tty_struct
*tty
);
475 static int stl_charsinbuffer(struct tty_struct
*tty
);
476 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
);
477 static void stl_settermios(struct tty_struct
*tty
, struct termios
*old
);
478 static void stl_throttle(struct tty_struct
*tty
);
479 static void stl_unthrottle(struct tty_struct
*tty
);
480 static void stl_stop(struct tty_struct
*tty
);
481 static void stl_start(struct tty_struct
*tty
);
482 static void stl_flushbuffer(struct tty_struct
*tty
);
483 static void stl_breakctl(struct tty_struct
*tty
, int state
);
484 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
);
485 static void stl_sendxchar(struct tty_struct
*tty
, char ch
);
486 static void stl_hangup(struct tty_struct
*tty
);
487 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
);
488 static int stl_portinfo(stlport_t
*portp
, int portnr
, char *pos
);
489 static int stl_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
);
491 static int stl_brdinit(stlbrd_t
*brdp
);
492 static int stl_initports(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
493 static int stl_getserial(stlport_t
*portp
, struct serial_struct __user
*sp
);
494 static int stl_setserial(stlport_t
*portp
, struct serial_struct __user
*sp
);
495 static int stl_getbrdstats(combrd_t __user
*bp
);
496 static int stl_getportstats(stlport_t
*portp
, comstats_t __user
*cp
);
497 static int stl_clrportstats(stlport_t
*portp
, comstats_t __user
*cp
);
498 static int stl_getportstruct(stlport_t __user
*arg
);
499 static int stl_getbrdstruct(stlbrd_t __user
*arg
);
500 static int stl_waitcarrier(stlport_t
*portp
, struct file
*filp
);
501 static int stl_eiointr(stlbrd_t
*brdp
);
502 static int stl_echatintr(stlbrd_t
*brdp
);
503 static int stl_echmcaintr(stlbrd_t
*brdp
);
504 static int stl_echpciintr(stlbrd_t
*brdp
);
505 static int stl_echpci64intr(stlbrd_t
*brdp
);
506 static void stl_offintr(void *private);
507 static void *stl_memalloc(int len
);
508 static stlbrd_t
*stl_allocbrd(void);
509 static stlport_t
*stl_getport(int brdnr
, int panelnr
, int portnr
);
511 static inline int stl_initbrds(void);
512 static inline int stl_initeio(stlbrd_t
*brdp
);
513 static inline int stl_initech(stlbrd_t
*brdp
);
514 static inline int stl_getbrdnr(void);
517 static inline int stl_findpcibrds(void);
518 static inline int stl_initpcibrd(int brdtype
, struct pci_dev
*devp
);
522 * CD1400 uart specific handling functions.
524 static void stl_cd1400setreg(stlport_t
*portp
, int regnr
, int value
);
525 static int stl_cd1400getreg(stlport_t
*portp
, int regnr
);
526 static int stl_cd1400updatereg(stlport_t
*portp
, int regnr
, int value
);
527 static int stl_cd1400panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
528 static void stl_cd1400portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
529 static void stl_cd1400setport(stlport_t
*portp
, struct termios
*tiosp
);
530 static int stl_cd1400getsignals(stlport_t
*portp
);
531 static void stl_cd1400setsignals(stlport_t
*portp
, int dtr
, int rts
);
532 static void stl_cd1400ccrwait(stlport_t
*portp
);
533 static void stl_cd1400enablerxtx(stlport_t
*portp
, int rx
, int tx
);
534 static void stl_cd1400startrxtx(stlport_t
*portp
, int rx
, int tx
);
535 static void stl_cd1400disableintrs(stlport_t
*portp
);
536 static void stl_cd1400sendbreak(stlport_t
*portp
, int len
);
537 static void stl_cd1400flowctrl(stlport_t
*portp
, int state
);
538 static void stl_cd1400sendflow(stlport_t
*portp
, int state
);
539 static void stl_cd1400flush(stlport_t
*portp
);
540 static int stl_cd1400datastate(stlport_t
*portp
);
541 static void stl_cd1400eiointr(stlpanel_t
*panelp
, unsigned int iobase
);
542 static void stl_cd1400echintr(stlpanel_t
*panelp
, unsigned int iobase
);
543 static void stl_cd1400txisr(stlpanel_t
*panelp
, int ioaddr
);
544 static void stl_cd1400rxisr(stlpanel_t
*panelp
, int ioaddr
);
545 static void stl_cd1400mdmisr(stlpanel_t
*panelp
, int ioaddr
);
547 static inline int stl_cd1400breakisr(stlport_t
*portp
, int ioaddr
);
550 * SC26198 uart specific handling functions.
552 static void stl_sc26198setreg(stlport_t
*portp
, int regnr
, int value
);
553 static int stl_sc26198getreg(stlport_t
*portp
, int regnr
);
554 static int stl_sc26198updatereg(stlport_t
*portp
, int regnr
, int value
);
555 static int stl_sc26198getglobreg(stlport_t
*portp
, int regnr
);
556 static int stl_sc26198panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
557 static void stl_sc26198portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
558 static void stl_sc26198setport(stlport_t
*portp
, struct termios
*tiosp
);
559 static int stl_sc26198getsignals(stlport_t
*portp
);
560 static void stl_sc26198setsignals(stlport_t
*portp
, int dtr
, int rts
);
561 static void stl_sc26198enablerxtx(stlport_t
*portp
, int rx
, int tx
);
562 static void stl_sc26198startrxtx(stlport_t
*portp
, int rx
, int tx
);
563 static void stl_sc26198disableintrs(stlport_t
*portp
);
564 static void stl_sc26198sendbreak(stlport_t
*portp
, int len
);
565 static void stl_sc26198flowctrl(stlport_t
*portp
, int state
);
566 static void stl_sc26198sendflow(stlport_t
*portp
, int state
);
567 static void stl_sc26198flush(stlport_t
*portp
);
568 static int stl_sc26198datastate(stlport_t
*portp
);
569 static void stl_sc26198wait(stlport_t
*portp
);
570 static void stl_sc26198txunflow(stlport_t
*portp
, struct tty_struct
*tty
);
571 static void stl_sc26198intr(stlpanel_t
*panelp
, unsigned int iobase
);
572 static void stl_sc26198txisr(stlport_t
*port
);
573 static void stl_sc26198rxisr(stlport_t
*port
, unsigned int iack
);
574 static void stl_sc26198rxbadch(stlport_t
*portp
, unsigned char status
, char ch
);
575 static void stl_sc26198rxbadchars(stlport_t
*portp
);
576 static void stl_sc26198otherisr(stlport_t
*port
, unsigned int iack
);
578 /*****************************************************************************/
581 * Generic UART support structure.
583 typedef struct uart
{
584 int (*panelinit
)(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
585 void (*portinit
)(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
586 void (*setport
)(stlport_t
*portp
, struct termios
*tiosp
);
587 int (*getsignals
)(stlport_t
*portp
);
588 void (*setsignals
)(stlport_t
*portp
, int dtr
, int rts
);
589 void (*enablerxtx
)(stlport_t
*portp
, int rx
, int tx
);
590 void (*startrxtx
)(stlport_t
*portp
, int rx
, int tx
);
591 void (*disableintrs
)(stlport_t
*portp
);
592 void (*sendbreak
)(stlport_t
*portp
, int len
);
593 void (*flowctrl
)(stlport_t
*portp
, int state
);
594 void (*sendflow
)(stlport_t
*portp
, int state
);
595 void (*flush
)(stlport_t
*portp
);
596 int (*datastate
)(stlport_t
*portp
);
597 void (*intr
)(stlpanel_t
*panelp
, unsigned int iobase
);
601 * Define some macros to make calling these functions nice and clean.
603 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
604 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
605 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
606 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
607 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
608 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
609 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
610 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
611 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
612 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
613 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
614 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
615 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
617 /*****************************************************************************/
620 * CD1400 UART specific data initialization.
622 static uart_t stl_cd1400uart
= {
626 stl_cd1400getsignals
,
627 stl_cd1400setsignals
,
628 stl_cd1400enablerxtx
,
630 stl_cd1400disableintrs
,
640 * Define the offsets within the register bank of a cd1400 based panel.
641 * These io address offsets are common to the EasyIO board as well.
649 #define EREG_BANKSIZE 8
651 #define CD1400_CLK 25000000
652 #define CD1400_CLK8M 20000000
655 * Define the cd1400 baud rate clocks. These are used when calculating
656 * what clock and divisor to use for the required baud rate. Also
657 * define the maximum baud rate allowed, and the default base baud.
659 static int stl_cd1400clkdivs
[] = {
660 CD1400_CLK0
, CD1400_CLK1
, CD1400_CLK2
, CD1400_CLK3
, CD1400_CLK4
663 /*****************************************************************************/
666 * SC26198 UART specific data initization.
668 static uart_t stl_sc26198uart
= {
669 stl_sc26198panelinit
,
672 stl_sc26198getsignals
,
673 stl_sc26198setsignals
,
674 stl_sc26198enablerxtx
,
675 stl_sc26198startrxtx
,
676 stl_sc26198disableintrs
,
677 stl_sc26198sendbreak
,
681 stl_sc26198datastate
,
686 * Define the offsets within the register bank of a sc26198 based panel.
694 #define XP_BANKSIZE 4
697 * Define the sc26198 baud rate table. Offsets within the table
698 * represent the actual baud rate selector of sc26198 registers.
700 static unsigned int sc26198_baudtable
[] = {
701 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
702 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
703 230400, 460800, 921600
706 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
708 /*****************************************************************************/
711 * Define the driver info for a user level control device. Used mainly
712 * to get at port stats - only not using the port device itself.
714 static struct file_operations stl_fsiomem
= {
715 .owner
= THIS_MODULE
,
716 .ioctl
= stl_memioctl
,
719 /*****************************************************************************/
721 static struct class *stallion_class
;
724 * Loadable module initialization stuff.
727 static int __init
stallion_module_init(void)
732 printk("init_module()\n");
738 restore_flags(flags
);
743 /*****************************************************************************/
745 static void __exit
stallion_module_exit(void)
754 printk("cleanup_module()\n");
757 printk(KERN_INFO
"Unloading %s: version %s\n", stl_drvtitle
,
764 * Free up all allocated resources used by the ports. This includes
765 * memory and interrupts. As part of this process we will also do
766 * a hangup on every open port - to try to flush out any processes
767 * hanging onto ports.
769 i
= tty_unregister_driver(stl_serial
);
770 put_tty_driver(stl_serial
);
772 printk("STALLION: failed to un-register tty driver, "
774 restore_flags(flags
);
777 for (i
= 0; i
< 4; i
++) {
778 devfs_remove("staliomem/%d", i
);
779 class_device_destroy(stallion_class
, MKDEV(STL_SIOMEMMAJOR
, i
));
781 devfs_remove("staliomem");
782 if ((i
= unregister_chrdev(STL_SIOMEMMAJOR
, "staliomem")))
783 printk("STALLION: failed to un-register serial memory device, "
785 class_destroy(stallion_class
);
787 kfree(stl_tmpwritebuf
);
789 for (i
= 0; (i
< stl_nrbrds
); i
++) {
790 if ((brdp
= stl_brds
[i
]) == (stlbrd_t
*) NULL
)
793 free_irq(brdp
->irq
, brdp
);
795 for (j
= 0; (j
< STL_MAXPANELS
); j
++) {
796 panelp
= brdp
->panels
[j
];
797 if (panelp
== (stlpanel_t
*) NULL
)
799 for (k
= 0; (k
< STL_PORTSPERPANEL
); k
++) {
800 portp
= panelp
->ports
[k
];
801 if (portp
== (stlport_t
*) NULL
)
803 if (portp
->tty
!= (struct tty_struct
*) NULL
)
804 stl_hangup(portp
->tty
);
805 kfree(portp
->tx
.buf
);
811 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
812 if (brdp
->iosize2
> 0)
813 release_region(brdp
->ioaddr2
, brdp
->iosize2
);
816 stl_brds
[i
] = (stlbrd_t
*) NULL
;
819 restore_flags(flags
);
822 module_init(stallion_module_init
);
823 module_exit(stallion_module_exit
);
825 /*****************************************************************************/
828 * Check for any arguments passed in on the module load command line.
831 static void stl_argbrds(void)
838 printk("stl_argbrds()\n");
841 for (i
= stl_nrbrds
; (i
< stl_nargs
); i
++) {
842 memset(&conf
, 0, sizeof(conf
));
843 if (stl_parsebrd(&conf
, stl_brdsp
[i
]) == 0)
845 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
849 brdp
->brdtype
= conf
.brdtype
;
850 brdp
->ioaddr1
= conf
.ioaddr1
;
851 brdp
->ioaddr2
= conf
.ioaddr2
;
852 brdp
->irq
= conf
.irq
;
853 brdp
->irqtype
= conf
.irqtype
;
858 /*****************************************************************************/
861 * Convert an ascii string number into an unsigned long.
864 static unsigned long stl_atol(char *str
)
872 if ((*sp
== '0') && (*(sp
+1) == 'x')) {
875 } else if (*sp
== '0') {
882 for (; (*sp
!= 0); sp
++) {
883 c
= (*sp
> '9') ? (TOLOWER(*sp
) - 'a' + 10) : (*sp
- '0');
884 if ((c
< 0) || (c
>= base
)) {
885 printk("STALLION: invalid argument %s\n", str
);
889 val
= (val
* base
) + c
;
894 /*****************************************************************************/
897 * Parse the supplied argument string, into the board conf struct.
900 static int stl_parsebrd(stlconf_t
*confp
, char **argp
)
906 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp
, (int) argp
);
909 if ((argp
[0] == (char *) NULL
) || (*argp
[0] == 0))
912 for (sp
= argp
[0], i
= 0; ((*sp
!= 0) && (i
< 25)); sp
++, i
++)
915 for (i
= 0; i
< ARRAY_SIZE(stl_brdstr
); i
++) {
916 if (strcmp(stl_brdstr
[i
].name
, argp
[0]) == 0)
919 if (i
== ARRAY_SIZE(stl_brdstr
)) {
920 printk("STALLION: unknown board name, %s?\n", argp
[0]);
924 confp
->brdtype
= stl_brdstr
[i
].type
;
927 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
928 confp
->ioaddr1
= stl_atol(argp
[i
]);
930 if (confp
->brdtype
== BRD_ECH
) {
931 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
932 confp
->ioaddr2
= stl_atol(argp
[i
]);
935 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
936 confp
->irq
= stl_atol(argp
[i
]);
940 /*****************************************************************************/
943 * Local driver kernel memory allocation routine.
946 static void *stl_memalloc(int len
)
948 return (void *) kmalloc(len
, GFP_KERNEL
);
951 /*****************************************************************************/
954 * Allocate a new board structure. Fill out the basic info in it.
957 static stlbrd_t
*stl_allocbrd(void)
961 brdp
= (stlbrd_t
*) stl_memalloc(sizeof(stlbrd_t
));
962 if (brdp
== (stlbrd_t
*) NULL
) {
963 printk("STALLION: failed to allocate memory (size=%d)\n",
965 return (stlbrd_t
*) NULL
;
968 memset(brdp
, 0, sizeof(stlbrd_t
));
969 brdp
->magic
= STL_BOARDMAGIC
;
973 /*****************************************************************************/
975 static int stl_open(struct tty_struct
*tty
, struct file
*filp
)
979 unsigned int minordev
;
980 int brdnr
, panelnr
, portnr
, rc
;
983 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty
,
984 (int) filp
, tty
->name
);
987 minordev
= tty
->index
;
988 brdnr
= MINOR2BRD(minordev
);
989 if (brdnr
>= stl_nrbrds
)
991 brdp
= stl_brds
[brdnr
];
992 if (brdp
== (stlbrd_t
*) NULL
)
994 minordev
= MINOR2PORT(minordev
);
995 for (portnr
= -1, panelnr
= 0; (panelnr
< STL_MAXPANELS
); panelnr
++) {
996 if (brdp
->panels
[panelnr
] == (stlpanel_t
*) NULL
)
998 if (minordev
< brdp
->panels
[panelnr
]->nrports
) {
1002 minordev
-= brdp
->panels
[panelnr
]->nrports
;
1007 portp
= brdp
->panels
[panelnr
]->ports
[portnr
];
1008 if (portp
== (stlport_t
*) NULL
)
1012 * On the first open of the device setup the port hardware, and
1013 * initialize the per port data structure.
1016 tty
->driver_data
= portp
;
1019 if ((portp
->flags
& ASYNC_INITIALIZED
) == 0) {
1020 if (portp
->tx
.buf
== (char *) NULL
) {
1021 portp
->tx
.buf
= (char *) stl_memalloc(STL_TXBUFSIZE
);
1022 if (portp
->tx
.buf
== (char *) NULL
)
1024 portp
->tx
.head
= portp
->tx
.buf
;
1025 portp
->tx
.tail
= portp
->tx
.buf
;
1027 stl_setport(portp
, tty
->termios
);
1028 portp
->sigs
= stl_getsignals(portp
);
1029 stl_setsignals(portp
, 1, 1);
1030 stl_enablerxtx(portp
, 1, 1);
1031 stl_startrxtx(portp
, 1, 0);
1032 clear_bit(TTY_IO_ERROR
, &tty
->flags
);
1033 portp
->flags
|= ASYNC_INITIALIZED
;
1037 * Check if this port is in the middle of closing. If so then wait
1038 * until it is closed then return error status, based on flag settings.
1039 * The sleep here does not need interrupt protection since the wakeup
1040 * for it is done with the same context.
1042 if (portp
->flags
& ASYNC_CLOSING
) {
1043 interruptible_sleep_on(&portp
->close_wait
);
1044 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1046 return -ERESTARTSYS
;
1050 * Based on type of open being done check if it can overlap with any
1051 * previous opens still in effect. If we are a normal serial device
1052 * then also we might have to wait for carrier.
1054 if (!(filp
->f_flags
& O_NONBLOCK
)) {
1055 if ((rc
= stl_waitcarrier(portp
, filp
)) != 0)
1058 portp
->flags
|= ASYNC_NORMAL_ACTIVE
;
1063 /*****************************************************************************/
1066 * Possibly need to wait for carrier (DCD signal) to come high. Say
1067 * maybe because if we are clocal then we don't need to wait...
1070 static int stl_waitcarrier(stlport_t
*portp
, struct file
*filp
)
1072 unsigned long flags
;
1076 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp
, (int) filp
);
1082 if (portp
->tty
->termios
->c_cflag
& CLOCAL
)
1087 portp
->openwaitcnt
++;
1088 if (! tty_hung_up_p(filp
))
1092 stl_setsignals(portp
, 1, 1);
1093 if (tty_hung_up_p(filp
) ||
1094 ((portp
->flags
& ASYNC_INITIALIZED
) == 0)) {
1095 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1101 if (((portp
->flags
& ASYNC_CLOSING
) == 0) &&
1102 (doclocal
|| (portp
->sigs
& TIOCM_CD
))) {
1105 if (signal_pending(current
)) {
1109 interruptible_sleep_on(&portp
->open_wait
);
1112 if (! tty_hung_up_p(filp
))
1114 portp
->openwaitcnt
--;
1115 restore_flags(flags
);
1120 /*****************************************************************************/
1122 static void stl_close(struct tty_struct
*tty
, struct file
*filp
)
1125 unsigned long flags
;
1128 printk("stl_close(tty=%x,filp=%x)\n", (int) tty
, (int) filp
);
1131 portp
= tty
->driver_data
;
1132 if (portp
== (stlport_t
*) NULL
)
1137 if (tty_hung_up_p(filp
)) {
1138 restore_flags(flags
);
1141 if ((tty
->count
== 1) && (portp
->refcount
!= 1))
1142 portp
->refcount
= 1;
1143 if (portp
->refcount
-- > 1) {
1144 restore_flags(flags
);
1148 portp
->refcount
= 0;
1149 portp
->flags
|= ASYNC_CLOSING
;
1152 * May want to wait for any data to drain before closing. The BUSY
1153 * flag keeps track of whether we are still sending or not - it is
1154 * very accurate for the cd1400, not quite so for the sc26198.
1155 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1158 if (portp
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1159 tty_wait_until_sent(tty
, portp
->closing_wait
);
1160 stl_waituntilsent(tty
, (HZ
/ 2));
1162 portp
->flags
&= ~ASYNC_INITIALIZED
;
1163 stl_disableintrs(portp
);
1164 if (tty
->termios
->c_cflag
& HUPCL
)
1165 stl_setsignals(portp
, 0, 0);
1166 stl_enablerxtx(portp
, 0, 0);
1167 stl_flushbuffer(tty
);
1169 if (portp
->tx
.buf
!= (char *) NULL
) {
1170 kfree(portp
->tx
.buf
);
1171 portp
->tx
.buf
= (char *) NULL
;
1172 portp
->tx
.head
= (char *) NULL
;
1173 portp
->tx
.tail
= (char *) NULL
;
1175 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1176 tty_ldisc_flush(tty
);
1179 portp
->tty
= (struct tty_struct
*) NULL
;
1181 if (portp
->openwaitcnt
) {
1182 if (portp
->close_delay
)
1183 msleep_interruptible(jiffies_to_msecs(portp
->close_delay
));
1184 wake_up_interruptible(&portp
->open_wait
);
1187 portp
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1188 wake_up_interruptible(&portp
->close_wait
);
1189 restore_flags(flags
);
1192 /*****************************************************************************/
1195 * Write routine. Take data and stuff it in to the TX ring queue.
1196 * If transmit interrupts are not running then start them.
1199 static int stl_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
1202 unsigned int len
, stlen
;
1203 unsigned char *chbuf
;
1207 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1208 (int) tty
, (int) buf
, count
);
1211 if ((tty
== (struct tty_struct
*) NULL
) ||
1212 (stl_tmpwritebuf
== (char *) NULL
))
1214 portp
= tty
->driver_data
;
1215 if (portp
== (stlport_t
*) NULL
)
1217 if (portp
->tx
.buf
== (char *) NULL
)
1221 * If copying direct from user space we must cater for page faults,
1222 * causing us to "sleep" here for a while. To handle this copy in all
1223 * the data we need now, into a local buffer. Then when we got it all
1224 * copy it into the TX buffer.
1226 chbuf
= (unsigned char *) buf
;
1228 head
= portp
->tx
.head
;
1229 tail
= portp
->tx
.tail
;
1231 len
= STL_TXBUFSIZE
- (head
- tail
) - 1;
1232 stlen
= STL_TXBUFSIZE
- (head
- portp
->tx
.buf
);
1234 len
= tail
- head
- 1;
1238 len
= MIN(len
, count
);
1241 stlen
= MIN(len
, stlen
);
1242 memcpy(head
, chbuf
, stlen
);
1247 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
)) {
1248 head
= portp
->tx
.buf
;
1249 stlen
= tail
- head
;
1252 portp
->tx
.head
= head
;
1254 clear_bit(ASYI_TXLOW
, &portp
->istate
);
1255 stl_startrxtx(portp
, -1, 1);
1260 /*****************************************************************************/
1262 static void stl_putchar(struct tty_struct
*tty
, unsigned char ch
)
1269 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty
, (int) ch
);
1272 if (tty
== (struct tty_struct
*) NULL
)
1274 portp
= tty
->driver_data
;
1275 if (portp
== (stlport_t
*) NULL
)
1277 if (portp
->tx
.buf
== (char *) NULL
)
1280 head
= portp
->tx
.head
;
1281 tail
= portp
->tx
.tail
;
1283 len
= (head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
)) : (tail
- head
);
1288 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
1289 head
= portp
->tx
.buf
;
1291 portp
->tx
.head
= head
;
1294 /*****************************************************************************/
1297 * If there are any characters in the buffer then make sure that TX
1298 * interrupts are on and get'em out. Normally used after the putchar
1299 * routine has been called.
1302 static void stl_flushchars(struct tty_struct
*tty
)
1307 printk("stl_flushchars(tty=%x)\n", (int) tty
);
1310 if (tty
== (struct tty_struct
*) NULL
)
1312 portp
= tty
->driver_data
;
1313 if (portp
== (stlport_t
*) NULL
)
1315 if (portp
->tx
.buf
== (char *) NULL
)
1319 if (tty
->stopped
|| tty
->hw_stopped
||
1320 (portp
->tx
.head
== portp
->tx
.tail
))
1323 stl_startrxtx(portp
, -1, 1);
1326 /*****************************************************************************/
1328 static int stl_writeroom(struct tty_struct
*tty
)
1334 printk("stl_writeroom(tty=%x)\n", (int) tty
);
1337 if (tty
== (struct tty_struct
*) NULL
)
1339 portp
= tty
->driver_data
;
1340 if (portp
== (stlport_t
*) NULL
)
1342 if (portp
->tx
.buf
== (char *) NULL
)
1345 head
= portp
->tx
.head
;
1346 tail
= portp
->tx
.tail
;
1347 return ((head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
) - 1) : (tail
- head
- 1));
1350 /*****************************************************************************/
1353 * Return number of chars in the TX buffer. Normally we would just
1354 * calculate the number of chars in the buffer and return that, but if
1355 * the buffer is empty and TX interrupts are still on then we return
1356 * that the buffer still has 1 char in it. This way whoever called us
1357 * will not think that ALL chars have drained - since the UART still
1358 * must have some chars in it (we are busy after all).
1361 static int stl_charsinbuffer(struct tty_struct
*tty
)
1368 printk("stl_charsinbuffer(tty=%x)\n", (int) tty
);
1371 if (tty
== (struct tty_struct
*) NULL
)
1373 portp
= tty
->driver_data
;
1374 if (portp
== (stlport_t
*) NULL
)
1376 if (portp
->tx
.buf
== (char *) NULL
)
1379 head
= portp
->tx
.head
;
1380 tail
= portp
->tx
.tail
;
1381 size
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
1382 if ((size
== 0) && test_bit(ASYI_TXBUSY
, &portp
->istate
))
1387 /*****************************************************************************/
1390 * Generate the serial struct info.
1393 static int stl_getserial(stlport_t
*portp
, struct serial_struct __user
*sp
)
1395 struct serial_struct sio
;
1399 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
1402 memset(&sio
, 0, sizeof(struct serial_struct
));
1403 sio
.line
= portp
->portnr
;
1404 sio
.port
= portp
->ioaddr
;
1405 sio
.flags
= portp
->flags
;
1406 sio
.baud_base
= portp
->baud_base
;
1407 sio
.close_delay
= portp
->close_delay
;
1408 sio
.closing_wait
= portp
->closing_wait
;
1409 sio
.custom_divisor
= portp
->custom_divisor
;
1411 if (portp
->uartp
== &stl_cd1400uart
) {
1412 sio
.type
= PORT_CIRRUS
;
1413 sio
.xmit_fifo_size
= CD1400_TXFIFOSIZE
;
1415 sio
.type
= PORT_UNKNOWN
;
1416 sio
.xmit_fifo_size
= SC26198_TXFIFOSIZE
;
1419 brdp
= stl_brds
[portp
->brdnr
];
1420 if (brdp
!= (stlbrd_t
*) NULL
)
1421 sio
.irq
= brdp
->irq
;
1423 return copy_to_user(sp
, &sio
, sizeof(struct serial_struct
)) ? -EFAULT
: 0;
1426 /*****************************************************************************/
1429 * Set port according to the serial struct info.
1430 * At this point we do not do any auto-configure stuff, so we will
1431 * just quietly ignore any requests to change irq, etc.
1434 static int stl_setserial(stlport_t
*portp
, struct serial_struct __user
*sp
)
1436 struct serial_struct sio
;
1439 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
1442 if (copy_from_user(&sio
, sp
, sizeof(struct serial_struct
)))
1444 if (!capable(CAP_SYS_ADMIN
)) {
1445 if ((sio
.baud_base
!= portp
->baud_base
) ||
1446 (sio
.close_delay
!= portp
->close_delay
) ||
1447 ((sio
.flags
& ~ASYNC_USR_MASK
) !=
1448 (portp
->flags
& ~ASYNC_USR_MASK
)))
1452 portp
->flags
= (portp
->flags
& ~ASYNC_USR_MASK
) |
1453 (sio
.flags
& ASYNC_USR_MASK
);
1454 portp
->baud_base
= sio
.baud_base
;
1455 portp
->close_delay
= sio
.close_delay
;
1456 portp
->closing_wait
= sio
.closing_wait
;
1457 portp
->custom_divisor
= sio
.custom_divisor
;
1458 stl_setport(portp
, portp
->tty
->termios
);
1462 /*****************************************************************************/
1464 static int stl_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1468 if (tty
== (struct tty_struct
*) NULL
)
1470 portp
= tty
->driver_data
;
1471 if (portp
== (stlport_t
*) NULL
)
1473 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1476 return stl_getsignals(portp
);
1479 static int stl_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1480 unsigned int set
, unsigned int clear
)
1483 int rts
= -1, dtr
= -1;
1485 if (tty
== (struct tty_struct
*) NULL
)
1487 portp
= tty
->driver_data
;
1488 if (portp
== (stlport_t
*) NULL
)
1490 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1493 if (set
& TIOCM_RTS
)
1495 if (set
& TIOCM_DTR
)
1497 if (clear
& TIOCM_RTS
)
1499 if (clear
& TIOCM_DTR
)
1502 stl_setsignals(portp
, dtr
, rts
);
1506 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1511 void __user
*argp
= (void __user
*)arg
;
1514 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1515 (int) tty
, (int) file
, cmd
, (int) arg
);
1518 if (tty
== (struct tty_struct
*) NULL
)
1520 portp
= tty
->driver_data
;
1521 if (portp
== (stlport_t
*) NULL
)
1524 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1525 (cmd
!= COM_GETPORTSTATS
) && (cmd
!= COM_CLRPORTSTATS
)) {
1526 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1534 rc
= put_user(((tty
->termios
->c_cflag
& CLOCAL
) ? 1 : 0),
1535 (unsigned __user
*) argp
);
1538 if (get_user(ival
, (unsigned int __user
*) arg
))
1540 tty
->termios
->c_cflag
=
1541 (tty
->termios
->c_cflag
& ~CLOCAL
) |
1542 (ival
? CLOCAL
: 0);
1545 rc
= stl_getserial(portp
, argp
);
1548 rc
= stl_setserial(portp
, argp
);
1550 case COM_GETPORTSTATS
:
1551 rc
= stl_getportstats(portp
, argp
);
1553 case COM_CLRPORTSTATS
:
1554 rc
= stl_clrportstats(portp
, argp
);
1560 case TIOCSERGSTRUCT
:
1561 case TIOCSERGETMULTI
:
1562 case TIOCSERSETMULTI
:
1571 /*****************************************************************************/
1573 static void stl_settermios(struct tty_struct
*tty
, struct termios
*old
)
1576 struct termios
*tiosp
;
1579 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty
, (int) old
);
1582 if (tty
== (struct tty_struct
*) NULL
)
1584 portp
= tty
->driver_data
;
1585 if (portp
== (stlport_t
*) NULL
)
1588 tiosp
= tty
->termios
;
1589 if ((tiosp
->c_cflag
== old
->c_cflag
) &&
1590 (tiosp
->c_iflag
== old
->c_iflag
))
1593 stl_setport(portp
, tiosp
);
1594 stl_setsignals(portp
, ((tiosp
->c_cflag
& (CBAUD
& ~CBAUDEX
)) ? 1 : 0),
1596 if ((old
->c_cflag
& CRTSCTS
) && ((tiosp
->c_cflag
& CRTSCTS
) == 0)) {
1597 tty
->hw_stopped
= 0;
1600 if (((old
->c_cflag
& CLOCAL
) == 0) && (tiosp
->c_cflag
& CLOCAL
))
1601 wake_up_interruptible(&portp
->open_wait
);
1604 /*****************************************************************************/
1607 * Attempt to flow control who ever is sending us data. Based on termios
1608 * settings use software or/and hardware flow control.
1611 static void stl_throttle(struct tty_struct
*tty
)
1616 printk("stl_throttle(tty=%x)\n", (int) tty
);
1619 if (tty
== (struct tty_struct
*) NULL
)
1621 portp
= tty
->driver_data
;
1622 if (portp
== (stlport_t
*) NULL
)
1624 stl_flowctrl(portp
, 0);
1627 /*****************************************************************************/
1630 * Unflow control the device sending us data...
1633 static void stl_unthrottle(struct tty_struct
*tty
)
1638 printk("stl_unthrottle(tty=%x)\n", (int) tty
);
1641 if (tty
== (struct tty_struct
*) NULL
)
1643 portp
= tty
->driver_data
;
1644 if (portp
== (stlport_t
*) NULL
)
1646 stl_flowctrl(portp
, 1);
1649 /*****************************************************************************/
1652 * Stop the transmitter. Basically to do this we will just turn TX
1656 static void stl_stop(struct tty_struct
*tty
)
1661 printk("stl_stop(tty=%x)\n", (int) tty
);
1664 if (tty
== (struct tty_struct
*) NULL
)
1666 portp
= tty
->driver_data
;
1667 if (portp
== (stlport_t
*) NULL
)
1669 stl_startrxtx(portp
, -1, 0);
1672 /*****************************************************************************/
1675 * Start the transmitter again. Just turn TX interrupts back on.
1678 static void stl_start(struct tty_struct
*tty
)
1683 printk("stl_start(tty=%x)\n", (int) tty
);
1686 if (tty
== (struct tty_struct
*) NULL
)
1688 portp
= tty
->driver_data
;
1689 if (portp
== (stlport_t
*) NULL
)
1691 stl_startrxtx(portp
, -1, 1);
1694 /*****************************************************************************/
1697 * Hangup this port. This is pretty much like closing the port, only
1698 * a little more brutal. No waiting for data to drain. Shutdown the
1699 * port and maybe drop signals.
1702 static void stl_hangup(struct tty_struct
*tty
)
1707 printk("stl_hangup(tty=%x)\n", (int) tty
);
1710 if (tty
== (struct tty_struct
*) NULL
)
1712 portp
= tty
->driver_data
;
1713 if (portp
== (stlport_t
*) NULL
)
1716 portp
->flags
&= ~ASYNC_INITIALIZED
;
1717 stl_disableintrs(portp
);
1718 if (tty
->termios
->c_cflag
& HUPCL
)
1719 stl_setsignals(portp
, 0, 0);
1720 stl_enablerxtx(portp
, 0, 0);
1721 stl_flushbuffer(tty
);
1723 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1724 if (portp
->tx
.buf
!= (char *) NULL
) {
1725 kfree(portp
->tx
.buf
);
1726 portp
->tx
.buf
= (char *) NULL
;
1727 portp
->tx
.head
= (char *) NULL
;
1728 portp
->tx
.tail
= (char *) NULL
;
1730 portp
->tty
= (struct tty_struct
*) NULL
;
1731 portp
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1732 portp
->refcount
= 0;
1733 wake_up_interruptible(&portp
->open_wait
);
1736 /*****************************************************************************/
1738 static void stl_flushbuffer(struct tty_struct
*tty
)
1743 printk("stl_flushbuffer(tty=%x)\n", (int) tty
);
1746 if (tty
== (struct tty_struct
*) NULL
)
1748 portp
= tty
->driver_data
;
1749 if (portp
== (stlport_t
*) NULL
)
1756 /*****************************************************************************/
1758 static void stl_breakctl(struct tty_struct
*tty
, int state
)
1763 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty
, state
);
1766 if (tty
== (struct tty_struct
*) NULL
)
1768 portp
= tty
->driver_data
;
1769 if (portp
== (stlport_t
*) NULL
)
1772 stl_sendbreak(portp
, ((state
== -1) ? 1 : 2));
1775 /*****************************************************************************/
1777 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
)
1783 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty
, timeout
);
1786 if (tty
== (struct tty_struct
*) NULL
)
1788 portp
= tty
->driver_data
;
1789 if (portp
== (stlport_t
*) NULL
)
1794 tend
= jiffies
+ timeout
;
1796 while (stl_datastate(portp
)) {
1797 if (signal_pending(current
))
1799 msleep_interruptible(20);
1800 if (time_after_eq(jiffies
, tend
))
1805 /*****************************************************************************/
1807 static void stl_sendxchar(struct tty_struct
*tty
, char ch
)
1812 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty
, ch
);
1815 if (tty
== (struct tty_struct
*) NULL
)
1817 portp
= tty
->driver_data
;
1818 if (portp
== (stlport_t
*) NULL
)
1821 if (ch
== STOP_CHAR(tty
))
1822 stl_sendflow(portp
, 0);
1823 else if (ch
== START_CHAR(tty
))
1824 stl_sendflow(portp
, 1);
1826 stl_putchar(tty
, ch
);
1829 /*****************************************************************************/
1834 * Format info for a specified port. The line is deliberately limited
1835 * to 80 characters. (If it is too long it will be truncated, if too
1836 * short then padded with spaces).
1839 static int stl_portinfo(stlport_t
*portp
, int portnr
, char *pos
)
1845 sp
+= sprintf(sp
, "%d: uart:%s tx:%d rx:%d",
1846 portnr
, (portp
->hwid
== 1) ? "SC26198" : "CD1400",
1847 (int) portp
->stats
.txtotal
, (int) portp
->stats
.rxtotal
);
1849 if (portp
->stats
.rxframing
)
1850 sp
+= sprintf(sp
, " fe:%d", (int) portp
->stats
.rxframing
);
1851 if (portp
->stats
.rxparity
)
1852 sp
+= sprintf(sp
, " pe:%d", (int) portp
->stats
.rxparity
);
1853 if (portp
->stats
.rxbreaks
)
1854 sp
+= sprintf(sp
, " brk:%d", (int) portp
->stats
.rxbreaks
);
1855 if (portp
->stats
.rxoverrun
)
1856 sp
+= sprintf(sp
, " oe:%d", (int) portp
->stats
.rxoverrun
);
1858 sigs
= stl_getsignals(portp
);
1859 cnt
= sprintf(sp
, "%s%s%s%s%s ",
1860 (sigs
& TIOCM_RTS
) ? "|RTS" : "",
1861 (sigs
& TIOCM_CTS
) ? "|CTS" : "",
1862 (sigs
& TIOCM_DTR
) ? "|DTR" : "",
1863 (sigs
& TIOCM_CD
) ? "|DCD" : "",
1864 (sigs
& TIOCM_DSR
) ? "|DSR" : "");
1868 for (cnt
= (sp
- pos
); (cnt
< (MAXLINE
- 1)); cnt
++)
1871 pos
[(MAXLINE
- 2)] = '+';
1872 pos
[(MAXLINE
- 1)] = '\n';
1877 /*****************************************************************************/
1880 * Port info, read from the /proc file system.
1883 static int stl_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
1888 int brdnr
, panelnr
, portnr
, totalport
;
1893 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1894 "data=%x\n", (int) page
, (int) start
, (int) off
, count
,
1895 (int) eof
, (int) data
);
1903 pos
+= sprintf(pos
, "%s: version %s", stl_drvtitle
,
1905 while (pos
< (page
+ MAXLINE
- 1))
1912 * We scan through for each board, panel and port. The offset is
1913 * calculated on the fly, and irrelevant ports are skipped.
1915 for (brdnr
= 0; (brdnr
< stl_nrbrds
); brdnr
++) {
1916 brdp
= stl_brds
[brdnr
];
1917 if (brdp
== (stlbrd_t
*) NULL
)
1919 if (brdp
->state
== 0)
1922 maxoff
= curoff
+ (brdp
->nrports
* MAXLINE
);
1923 if (off
>= maxoff
) {
1928 totalport
= brdnr
* STL_MAXPORTS
;
1929 for (panelnr
= 0; (panelnr
< brdp
->nrpanels
); panelnr
++) {
1930 panelp
= brdp
->panels
[panelnr
];
1931 if (panelp
== (stlpanel_t
*) NULL
)
1934 maxoff
= curoff
+ (panelp
->nrports
* MAXLINE
);
1935 if (off
>= maxoff
) {
1937 totalport
+= panelp
->nrports
;
1941 for (portnr
= 0; (portnr
< panelp
->nrports
); portnr
++,
1943 portp
= panelp
->ports
[portnr
];
1944 if (portp
== (stlport_t
*) NULL
)
1946 if (off
>= (curoff
+= MAXLINE
))
1948 if ((pos
- page
+ MAXLINE
) > count
)
1950 pos
+= stl_portinfo(portp
, totalport
, pos
);
1959 return (pos
- page
);
1962 /*****************************************************************************/
1965 * All board interrupts are vectored through here first. This code then
1966 * calls off to the approrpriate board interrupt handlers.
1969 static irqreturn_t
stl_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
1971 stlbrd_t
*brdp
= (stlbrd_t
*) dev_id
;
1974 printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp
, irq
,
1978 return IRQ_RETVAL((* brdp
->isr
)(brdp
));
1981 /*****************************************************************************/
1984 * Interrupt service routine for EasyIO board types.
1987 static int stl_eiointr(stlbrd_t
*brdp
)
1990 unsigned int iobase
;
1993 panelp
= brdp
->panels
[0];
1994 iobase
= panelp
->iobase
;
1995 while (inb(brdp
->iostatus
) & EIO_INTRPEND
) {
1997 (* panelp
->isr
)(panelp
, iobase
);
2002 /*****************************************************************************/
2005 * Interrupt service routine for ECH-AT board types.
2008 static int stl_echatintr(stlbrd_t
*brdp
)
2011 unsigned int ioaddr
;
2015 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
2017 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
2019 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2020 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2021 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2022 panelp
= brdp
->bnk2panel
[bnknr
];
2023 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2028 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
2033 /*****************************************************************************/
2036 * Interrupt service routine for ECH-MCA board types.
2039 static int stl_echmcaintr(stlbrd_t
*brdp
)
2042 unsigned int ioaddr
;
2046 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
2048 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2049 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2050 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2051 panelp
= brdp
->bnk2panel
[bnknr
];
2052 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2059 /*****************************************************************************/
2062 * Interrupt service routine for ECH-PCI board types.
2065 static int stl_echpciintr(stlbrd_t
*brdp
)
2068 unsigned int ioaddr
;
2074 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2075 outb(brdp
->bnkpageaddr
[bnknr
], brdp
->ioctrl
);
2076 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2077 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2078 panelp
= brdp
->bnk2panel
[bnknr
];
2079 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2090 /*****************************************************************************/
2093 * Interrupt service routine for ECH-8/64-PCI board types.
2096 static int stl_echpci64intr(stlbrd_t
*brdp
)
2099 unsigned int ioaddr
;
2103 while (inb(brdp
->ioctrl
) & 0x1) {
2105 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2106 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2107 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2108 panelp
= brdp
->bnk2panel
[bnknr
];
2109 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2117 /*****************************************************************************/
2120 * Service an off-level request for some channel.
2122 static void stl_offintr(void *private)
2125 struct tty_struct
*tty
;
2126 unsigned int oldsigs
;
2131 printk("stl_offintr(portp=%x)\n", (int) portp
);
2134 if (portp
== (stlport_t
*) NULL
)
2138 if (tty
== (struct tty_struct
*) NULL
)
2142 if (test_bit(ASYI_TXLOW
, &portp
->istate
)) {
2145 if (test_bit(ASYI_DCDCHANGE
, &portp
->istate
)) {
2146 clear_bit(ASYI_DCDCHANGE
, &portp
->istate
);
2147 oldsigs
= portp
->sigs
;
2148 portp
->sigs
= stl_getsignals(portp
);
2149 if ((portp
->sigs
& TIOCM_CD
) && ((oldsigs
& TIOCM_CD
) == 0))
2150 wake_up_interruptible(&portp
->open_wait
);
2151 if ((oldsigs
& TIOCM_CD
) && ((portp
->sigs
& TIOCM_CD
) == 0)) {
2152 if (portp
->flags
& ASYNC_CHECK_CD
)
2153 tty_hangup(tty
); /* FIXME: module removal race here - AKPM */
2159 /*****************************************************************************/
2162 * Initialize all the ports on a panel.
2165 static int __init
stl_initports(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
2171 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
2174 chipmask
= stl_panelinit(brdp
, panelp
);
2177 * All UART's are initialized (if found!). Now go through and setup
2178 * each ports data structures.
2180 for (i
= 0; (i
< panelp
->nrports
); i
++) {
2181 portp
= (stlport_t
*) stl_memalloc(sizeof(stlport_t
));
2182 if (portp
== (stlport_t
*) NULL
) {
2183 printk("STALLION: failed to allocate memory "
2184 "(size=%d)\n", sizeof(stlport_t
));
2187 memset(portp
, 0, sizeof(stlport_t
));
2189 portp
->magic
= STL_PORTMAGIC
;
2191 portp
->brdnr
= panelp
->brdnr
;
2192 portp
->panelnr
= panelp
->panelnr
;
2193 portp
->uartp
= panelp
->uartp
;
2194 portp
->clk
= brdp
->clk
;
2195 portp
->baud_base
= STL_BAUDBASE
;
2196 portp
->close_delay
= STL_CLOSEDELAY
;
2197 portp
->closing_wait
= 30 * HZ
;
2198 INIT_WORK(&portp
->tqueue
, stl_offintr
, portp
);
2199 init_waitqueue_head(&portp
->open_wait
);
2200 init_waitqueue_head(&portp
->close_wait
);
2201 portp
->stats
.brd
= portp
->brdnr
;
2202 portp
->stats
.panel
= portp
->panelnr
;
2203 portp
->stats
.port
= portp
->portnr
;
2204 panelp
->ports
[i
] = portp
;
2205 stl_portinit(brdp
, panelp
, portp
);
2211 /*****************************************************************************/
2214 * Try to find and initialize an EasyIO board.
2217 static inline int stl_initeio(stlbrd_t
*brdp
)
2220 unsigned int status
;
2225 printk("stl_initeio(brdp=%x)\n", (int) brdp
);
2228 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2229 brdp
->iostatus
= brdp
->ioaddr1
+ 2;
2231 status
= inb(brdp
->iostatus
);
2232 if ((status
& EIO_IDBITMASK
) == EIO_MK3
)
2236 * Handle board specific stuff now. The real difference is PCI
2239 if (brdp
->brdtype
== BRD_EASYIOPCI
) {
2240 brdp
->iosize1
= 0x80;
2241 brdp
->iosize2
= 0x80;
2242 name
= "serial(EIO-PCI)";
2243 outb(0x41, (brdp
->ioaddr2
+ 0x4c));
2246 name
= "serial(EIO)";
2247 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2248 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2249 printk("STALLION: invalid irq=%d for brd=%d\n",
2250 brdp
->irq
, brdp
->brdnr
);
2253 outb((stl_vecmap
[brdp
->irq
] | EIO_0WS
|
2254 ((brdp
->irqtype
) ? EIO_INTLEVEL
: EIO_INTEDGE
)),
2258 if (!request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
)) {
2259 printk(KERN_WARNING
"STALLION: Warning, board %d I/O address "
2260 "%x conflicts with another device\n", brdp
->brdnr
,
2265 if (brdp
->iosize2
> 0)
2266 if (!request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
)) {
2267 printk(KERN_WARNING
"STALLION: Warning, board %d I/O "
2268 "address %x conflicts with another device\n",
2269 brdp
->brdnr
, brdp
->ioaddr2
);
2270 printk(KERN_WARNING
"STALLION: Warning, also "
2271 "releasing board %d I/O address %x \n",
2272 brdp
->brdnr
, brdp
->ioaddr1
);
2273 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
2278 * Everything looks OK, so let's go ahead and probe for the hardware.
2280 brdp
->clk
= CD1400_CLK
;
2281 brdp
->isr
= stl_eiointr
;
2283 switch (status
& EIO_IDBITMASK
) {
2285 brdp
->clk
= CD1400_CLK8M
;
2295 switch (status
& EIO_BRDMASK
) {
2314 * We have verified that the board is actually present, so now we
2315 * can complete the setup.
2318 panelp
= (stlpanel_t
*) stl_memalloc(sizeof(stlpanel_t
));
2319 if (panelp
== (stlpanel_t
*) NULL
) {
2320 printk(KERN_WARNING
"STALLION: failed to allocate memory "
2321 "(size=%d)\n", sizeof(stlpanel_t
));
2324 memset(panelp
, 0, sizeof(stlpanel_t
));
2326 panelp
->magic
= STL_PANELMAGIC
;
2327 panelp
->brdnr
= brdp
->brdnr
;
2328 panelp
->panelnr
= 0;
2329 panelp
->nrports
= brdp
->nrports
;
2330 panelp
->iobase
= brdp
->ioaddr1
;
2331 panelp
->hwid
= status
;
2332 if ((status
& EIO_IDBITMASK
) == EIO_MK3
) {
2333 panelp
->uartp
= (void *) &stl_sc26198uart
;
2334 panelp
->isr
= stl_sc26198intr
;
2336 panelp
->uartp
= (void *) &stl_cd1400uart
;
2337 panelp
->isr
= stl_cd1400eiointr
;
2340 brdp
->panels
[0] = panelp
;
2342 brdp
->state
|= BRD_FOUND
;
2343 brdp
->hwid
= status
;
2344 if (request_irq(brdp
->irq
, stl_intr
, SA_SHIRQ
, name
, brdp
) != 0) {
2345 printk("STALLION: failed to register interrupt "
2346 "routine for %s irq=%d\n", name
, brdp
->irq
);
2354 /*****************************************************************************/
2357 * Try to find an ECH board and initialize it. This code is capable of
2358 * dealing with all types of ECH board.
2361 static inline int stl_initech(stlbrd_t
*brdp
)
2364 unsigned int status
, nxtid
, ioaddr
, conflict
;
2365 int panelnr
, banknr
, i
;
2369 printk("stl_initech(brdp=%x)\n", (int) brdp
);
2376 * Set up the initial board register contents for boards. This varies a
2377 * bit between the different board types. So we need to handle each
2378 * separately. Also do a check that the supplied IRQ is good.
2380 switch (brdp
->brdtype
) {
2383 brdp
->isr
= stl_echatintr
;
2384 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2385 brdp
->iostatus
= brdp
->ioaddr1
+ 1;
2386 status
= inb(brdp
->iostatus
);
2387 if ((status
& ECH_IDBITMASK
) != ECH_ID
)
2389 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2390 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2391 printk("STALLION: invalid irq=%d for brd=%d\n",
2392 brdp
->irq
, brdp
->brdnr
);
2395 status
= ((brdp
->ioaddr2
& ECH_ADDR2MASK
) >> 1);
2396 status
|= (stl_vecmap
[brdp
->irq
] << 1);
2397 outb((status
| ECH_BRDRESET
), brdp
->ioaddr1
);
2398 brdp
->ioctrlval
= ECH_INTENABLE
|
2399 ((brdp
->irqtype
) ? ECH_INTLEVEL
: ECH_INTEDGE
);
2400 for (i
= 0; (i
< 10); i
++)
2401 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
2404 name
= "serial(EC8/32)";
2405 outb(status
, brdp
->ioaddr1
);
2409 brdp
->isr
= stl_echmcaintr
;
2410 brdp
->ioctrl
= brdp
->ioaddr1
+ 0x20;
2411 brdp
->iostatus
= brdp
->ioctrl
;
2412 status
= inb(brdp
->iostatus
);
2413 if ((status
& ECH_IDBITMASK
) != ECH_ID
)
2415 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2416 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2417 printk("STALLION: invalid irq=%d for brd=%d\n",
2418 brdp
->irq
, brdp
->brdnr
);
2421 outb(ECHMC_BRDRESET
, brdp
->ioctrl
);
2422 outb(ECHMC_INTENABLE
, brdp
->ioctrl
);
2424 name
= "serial(EC8/32-MC)";
2428 brdp
->isr
= stl_echpciintr
;
2429 brdp
->ioctrl
= brdp
->ioaddr1
+ 2;
2432 name
= "serial(EC8/32-PCI)";
2436 brdp
->isr
= stl_echpci64intr
;
2437 brdp
->ioctrl
= brdp
->ioaddr2
+ 0x40;
2438 outb(0x43, (brdp
->ioaddr1
+ 0x4c));
2439 brdp
->iosize1
= 0x80;
2440 brdp
->iosize2
= 0x80;
2441 name
= "serial(EC8/64-PCI)";
2445 printk("STALLION: unknown board type=%d\n", brdp
->brdtype
);
2451 * Check boards for possible IO address conflicts and return fail status
2452 * if an IO conflict found.
2454 if (!request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
)) {
2455 printk(KERN_WARNING
"STALLION: Warning, board %d I/O address "
2456 "%x conflicts with another device\n", brdp
->brdnr
,
2461 if (brdp
->iosize2
> 0)
2462 if (!request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
)) {
2463 printk(KERN_WARNING
"STALLION: Warning, board %d I/O "
2464 "address %x conflicts with another device\n",
2465 brdp
->brdnr
, brdp
->ioaddr2
);
2466 printk(KERN_WARNING
"STALLION: Warning, also "
2467 "releasing board %d I/O address %x \n",
2468 brdp
->brdnr
, brdp
->ioaddr1
);
2469 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
2474 * Scan through the secondary io address space looking for panels.
2475 * As we find'em allocate and initialize panel structures for each.
2477 brdp
->clk
= CD1400_CLK
;
2478 brdp
->hwid
= status
;
2480 ioaddr
= brdp
->ioaddr2
;
2485 for (i
= 0; (i
< STL_MAXPANELS
); i
++) {
2486 if (brdp
->brdtype
== BRD_ECHPCI
) {
2487 outb(nxtid
, brdp
->ioctrl
);
2488 ioaddr
= brdp
->ioaddr2
;
2490 status
= inb(ioaddr
+ ECH_PNLSTATUS
);
2491 if ((status
& ECH_PNLIDMASK
) != nxtid
)
2493 panelp
= (stlpanel_t
*) stl_memalloc(sizeof(stlpanel_t
));
2494 if (panelp
== (stlpanel_t
*) NULL
) {
2495 printk("STALLION: failed to allocate memory "
2496 "(size=%d)\n", sizeof(stlpanel_t
));
2499 memset(panelp
, 0, sizeof(stlpanel_t
));
2500 panelp
->magic
= STL_PANELMAGIC
;
2501 panelp
->brdnr
= brdp
->brdnr
;
2502 panelp
->panelnr
= panelnr
;
2503 panelp
->iobase
= ioaddr
;
2504 panelp
->pagenr
= nxtid
;
2505 panelp
->hwid
= status
;
2506 brdp
->bnk2panel
[banknr
] = panelp
;
2507 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2508 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ ECH_PNLSTATUS
;
2510 if (status
& ECH_PNLXPID
) {
2511 panelp
->uartp
= (void *) &stl_sc26198uart
;
2512 panelp
->isr
= stl_sc26198intr
;
2513 if (status
& ECH_PNL16PORT
) {
2514 panelp
->nrports
= 16;
2515 brdp
->bnk2panel
[banknr
] = panelp
;
2516 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2517 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ 4 +
2520 panelp
->nrports
= 8;
2523 panelp
->uartp
= (void *) &stl_cd1400uart
;
2524 panelp
->isr
= stl_cd1400echintr
;
2525 if (status
& ECH_PNL16PORT
) {
2526 panelp
->nrports
= 16;
2527 panelp
->ackmask
= 0x80;
2528 if (brdp
->brdtype
!= BRD_ECHPCI
)
2529 ioaddr
+= EREG_BANKSIZE
;
2530 brdp
->bnk2panel
[banknr
] = panelp
;
2531 brdp
->bnkpageaddr
[banknr
] = ++nxtid
;
2532 brdp
->bnkstataddr
[banknr
++] = ioaddr
+
2535 panelp
->nrports
= 8;
2536 panelp
->ackmask
= 0xc0;
2541 ioaddr
+= EREG_BANKSIZE
;
2542 brdp
->nrports
+= panelp
->nrports
;
2543 brdp
->panels
[panelnr
++] = panelp
;
2544 if ((brdp
->brdtype
!= BRD_ECHPCI
) &&
2545 (ioaddr
>= (brdp
->ioaddr2
+ brdp
->iosize2
)))
2549 brdp
->nrpanels
= panelnr
;
2550 brdp
->nrbnks
= banknr
;
2551 if (brdp
->brdtype
== BRD_ECH
)
2552 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
2554 brdp
->state
|= BRD_FOUND
;
2555 if (request_irq(brdp
->irq
, stl_intr
, SA_SHIRQ
, name
, brdp
) != 0) {
2556 printk("STALLION: failed to register interrupt "
2557 "routine for %s irq=%d\n", name
, brdp
->irq
);
2566 /*****************************************************************************/
2569 * Initialize and configure the specified board.
2570 * Scan through all the boards in the configuration and see what we
2571 * can find. Handle EIO and the ECH boards a little differently here
2572 * since the initial search and setup is very different.
2575 static int __init
stl_brdinit(stlbrd_t
*brdp
)
2580 printk("stl_brdinit(brdp=%x)\n", (int) brdp
);
2583 switch (brdp
->brdtype
) {
2595 printk("STALLION: board=%d is unknown board type=%d\n",
2596 brdp
->brdnr
, brdp
->brdtype
);
2600 stl_brds
[brdp
->brdnr
] = brdp
;
2601 if ((brdp
->state
& BRD_FOUND
) == 0) {
2602 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2603 stl_brdnames
[brdp
->brdtype
], brdp
->brdnr
,
2604 brdp
->ioaddr1
, brdp
->irq
);
2608 for (i
= 0; (i
< STL_MAXPANELS
); i
++)
2609 if (brdp
->panels
[i
] != (stlpanel_t
*) NULL
)
2610 stl_initports(brdp
, brdp
->panels
[i
]);
2612 printk("STALLION: %s found, board=%d io=%x irq=%d "
2613 "nrpanels=%d nrports=%d\n", stl_brdnames
[brdp
->brdtype
],
2614 brdp
->brdnr
, brdp
->ioaddr1
, brdp
->irq
, brdp
->nrpanels
,
2619 /*****************************************************************************/
2622 * Find the next available board number that is free.
2625 static inline int stl_getbrdnr(void)
2629 for (i
= 0; (i
< STL_MAXBRDS
); i
++) {
2630 if (stl_brds
[i
] == (stlbrd_t
*) NULL
) {
2631 if (i
>= stl_nrbrds
)
2639 /*****************************************************************************/
2644 * We have a Stallion board. Allocate a board structure and
2645 * initialize it. Read its IO and IRQ resources from PCI
2646 * configuration space.
2649 static inline int stl_initpcibrd(int brdtype
, struct pci_dev
*devp
)
2654 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype
,
2655 devp
->bus
->number
, devp
->devfn
);
2658 if (pci_enable_device(devp
))
2660 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
2662 if ((brdp
->brdnr
= stl_getbrdnr()) < 0) {
2663 printk("STALLION: too many boards found, "
2664 "maximum supported %d\n", STL_MAXBRDS
);
2667 brdp
->brdtype
= brdtype
;
2670 * Different Stallion boards use the BAR registers in different ways,
2671 * so set up io addresses based on board type.
2674 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__
, __LINE__
,
2675 pci_resource_start(devp
, 0), pci_resource_start(devp
, 1),
2676 pci_resource_start(devp
, 2), pci_resource_start(devp
, 3), devp
->irq
);
2680 * We have all resources from the board, so let's setup the actual
2681 * board structure now.
2685 brdp
->ioaddr2
= pci_resource_start(devp
, 0);
2686 brdp
->ioaddr1
= pci_resource_start(devp
, 1);
2689 brdp
->ioaddr2
= pci_resource_start(devp
, 2);
2690 brdp
->ioaddr1
= pci_resource_start(devp
, 1);
2693 brdp
->ioaddr1
= pci_resource_start(devp
, 2);
2694 brdp
->ioaddr2
= pci_resource_start(devp
, 1);
2697 printk("STALLION: unknown PCI board type=%d\n", brdtype
);
2701 brdp
->irq
= devp
->irq
;
2707 /*****************************************************************************/
2710 * Find all Stallion PCI boards that might be installed. Initialize each
2711 * one as it is found.
2715 static inline int stl_findpcibrds(void)
2717 struct pci_dev
*dev
= NULL
;
2721 printk("stl_findpcibrds()\n");
2724 for (i
= 0; (i
< stl_nrpcibrds
); i
++)
2725 while ((dev
= pci_find_device(stl_pcibrds
[i
].vendid
,
2726 stl_pcibrds
[i
].devid
, dev
))) {
2729 * Found a device on the PCI bus that has our vendor and
2730 * device ID. Need to check now that it is really us.
2732 if ((dev
->class >> 8) == PCI_CLASS_STORAGE_IDE
)
2735 rc
= stl_initpcibrd(stl_pcibrds
[i
].brdtype
, dev
);
2745 /*****************************************************************************/
2748 * Scan through all the boards in the configuration and see what we
2749 * can find. Handle EIO and the ECH boards a little differently here
2750 * since the initial search and setup is too different.
2753 static inline int stl_initbrds(void)
2760 printk("stl_initbrds()\n");
2763 if (stl_nrbrds
> STL_MAXBRDS
) {
2764 printk("STALLION: too many boards in configuration table, "
2765 "truncating to %d\n", STL_MAXBRDS
);
2766 stl_nrbrds
= STL_MAXBRDS
;
2770 * Firstly scan the list of static boards configured. Allocate
2771 * resources and initialize the boards as found.
2773 for (i
= 0; (i
< stl_nrbrds
); i
++) {
2774 confp
= &stl_brdconf
[i
];
2775 stl_parsebrd(confp
, stl_brdsp
[i
]);
2776 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
2779 brdp
->brdtype
= confp
->brdtype
;
2780 brdp
->ioaddr1
= confp
->ioaddr1
;
2781 brdp
->ioaddr2
= confp
->ioaddr2
;
2782 brdp
->irq
= confp
->irq
;
2783 brdp
->irqtype
= confp
->irqtype
;
2788 * Find any dynamically supported boards. That is via module load
2789 * line options or auto-detected on the PCI bus.
2799 /*****************************************************************************/
2802 * Return the board stats structure to user app.
2805 static int stl_getbrdstats(combrd_t __user
*bp
)
2811 if (copy_from_user(&stl_brdstats
, bp
, sizeof(combrd_t
)))
2813 if (stl_brdstats
.brd
>= STL_MAXBRDS
)
2815 brdp
= stl_brds
[stl_brdstats
.brd
];
2816 if (brdp
== (stlbrd_t
*) NULL
)
2819 memset(&stl_brdstats
, 0, sizeof(combrd_t
));
2820 stl_brdstats
.brd
= brdp
->brdnr
;
2821 stl_brdstats
.type
= brdp
->brdtype
;
2822 stl_brdstats
.hwid
= brdp
->hwid
;
2823 stl_brdstats
.state
= brdp
->state
;
2824 stl_brdstats
.ioaddr
= brdp
->ioaddr1
;
2825 stl_brdstats
.ioaddr2
= brdp
->ioaddr2
;
2826 stl_brdstats
.irq
= brdp
->irq
;
2827 stl_brdstats
.nrpanels
= brdp
->nrpanels
;
2828 stl_brdstats
.nrports
= brdp
->nrports
;
2829 for (i
= 0; (i
< brdp
->nrpanels
); i
++) {
2830 panelp
= brdp
->panels
[i
];
2831 stl_brdstats
.panels
[i
].panel
= i
;
2832 stl_brdstats
.panels
[i
].hwid
= panelp
->hwid
;
2833 stl_brdstats
.panels
[i
].nrports
= panelp
->nrports
;
2836 return copy_to_user(bp
, &stl_brdstats
, sizeof(combrd_t
)) ? -EFAULT
: 0;
2839 /*****************************************************************************/
2842 * Resolve the referenced port number into a port struct pointer.
2845 static stlport_t
*stl_getport(int brdnr
, int panelnr
, int portnr
)
2850 if ((brdnr
< 0) || (brdnr
>= STL_MAXBRDS
))
2851 return((stlport_t
*) NULL
);
2852 brdp
= stl_brds
[brdnr
];
2853 if (brdp
== (stlbrd_t
*) NULL
)
2854 return((stlport_t
*) NULL
);
2855 if ((panelnr
< 0) || (panelnr
>= brdp
->nrpanels
))
2856 return((stlport_t
*) NULL
);
2857 panelp
= brdp
->panels
[panelnr
];
2858 if (panelp
== (stlpanel_t
*) NULL
)
2859 return((stlport_t
*) NULL
);
2860 if ((portnr
< 0) || (portnr
>= panelp
->nrports
))
2861 return((stlport_t
*) NULL
);
2862 return(panelp
->ports
[portnr
]);
2865 /*****************************************************************************/
2868 * Return the port stats structure to user app. A NULL port struct
2869 * pointer passed in means that we need to find out from the app
2870 * what port to get stats for (used through board control device).
2873 static int stl_getportstats(stlport_t
*portp
, comstats_t __user
*cp
)
2875 unsigned char *head
, *tail
;
2876 unsigned long flags
;
2879 if (copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
)))
2881 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
2883 if (portp
== (stlport_t
*) NULL
)
2887 portp
->stats
.state
= portp
->istate
;
2888 portp
->stats
.flags
= portp
->flags
;
2889 portp
->stats
.hwid
= portp
->hwid
;
2891 portp
->stats
.ttystate
= 0;
2892 portp
->stats
.cflags
= 0;
2893 portp
->stats
.iflags
= 0;
2894 portp
->stats
.oflags
= 0;
2895 portp
->stats
.lflags
= 0;
2896 portp
->stats
.rxbuffered
= 0;
2900 if (portp
->tty
!= (struct tty_struct
*) NULL
) {
2901 if (portp
->tty
->driver_data
== portp
) {
2902 portp
->stats
.ttystate
= portp
->tty
->flags
;
2903 /* No longer available as a statistic */
2904 portp
->stats
.rxbuffered
= 1; /*portp->tty->flip.count; */
2905 if (portp
->tty
->termios
!= (struct termios
*) NULL
) {
2906 portp
->stats
.cflags
= portp
->tty
->termios
->c_cflag
;
2907 portp
->stats
.iflags
= portp
->tty
->termios
->c_iflag
;
2908 portp
->stats
.oflags
= portp
->tty
->termios
->c_oflag
;
2909 portp
->stats
.lflags
= portp
->tty
->termios
->c_lflag
;
2913 restore_flags(flags
);
2915 head
= portp
->tx
.head
;
2916 tail
= portp
->tx
.tail
;
2917 portp
->stats
.txbuffered
= ((head
>= tail
) ? (head
- tail
) :
2918 (STL_TXBUFSIZE
- (tail
- head
)));
2920 portp
->stats
.signals
= (unsigned long) stl_getsignals(portp
);
2922 return copy_to_user(cp
, &portp
->stats
,
2923 sizeof(comstats_t
)) ? -EFAULT
: 0;
2926 /*****************************************************************************/
2929 * Clear the port stats structure. We also return it zeroed out...
2932 static int stl_clrportstats(stlport_t
*portp
, comstats_t __user
*cp
)
2935 if (copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
)))
2937 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
2939 if (portp
== (stlport_t
*) NULL
)
2943 memset(&portp
->stats
, 0, sizeof(comstats_t
));
2944 portp
->stats
.brd
= portp
->brdnr
;
2945 portp
->stats
.panel
= portp
->panelnr
;
2946 portp
->stats
.port
= portp
->portnr
;
2947 return copy_to_user(cp
, &portp
->stats
,
2948 sizeof(comstats_t
)) ? -EFAULT
: 0;
2951 /*****************************************************************************/
2954 * Return the entire driver ports structure to a user app.
2957 static int stl_getportstruct(stlport_t __user
*arg
)
2961 if (copy_from_user(&stl_dummyport
, arg
, sizeof(stlport_t
)))
2963 portp
= stl_getport(stl_dummyport
.brdnr
, stl_dummyport
.panelnr
,
2964 stl_dummyport
.portnr
);
2967 return copy_to_user(arg
, portp
, sizeof(stlport_t
)) ? -EFAULT
: 0;
2970 /*****************************************************************************/
2973 * Return the entire driver board structure to a user app.
2976 static int stl_getbrdstruct(stlbrd_t __user
*arg
)
2980 if (copy_from_user(&stl_dummybrd
, arg
, sizeof(stlbrd_t
)))
2982 if ((stl_dummybrd
.brdnr
< 0) || (stl_dummybrd
.brdnr
>= STL_MAXBRDS
))
2984 brdp
= stl_brds
[stl_dummybrd
.brdnr
];
2987 return copy_to_user(arg
, brdp
, sizeof(stlbrd_t
)) ? -EFAULT
: 0;
2990 /*****************************************************************************/
2993 * The "staliomem" device is also required to do some special operations
2994 * on the board and/or ports. In this driver it is mostly used for stats
2998 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
)
3001 void __user
*argp
= (void __user
*)arg
;
3004 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip
,
3005 (int) fp
, cmd
, (int) arg
);
3009 if (brdnr
>= STL_MAXBRDS
)
3014 case COM_GETPORTSTATS
:
3015 rc
= stl_getportstats(NULL
, argp
);
3017 case COM_CLRPORTSTATS
:
3018 rc
= stl_clrportstats(NULL
, argp
);
3020 case COM_GETBRDSTATS
:
3021 rc
= stl_getbrdstats(argp
);
3024 rc
= stl_getportstruct(argp
);
3027 rc
= stl_getbrdstruct(argp
);
3037 static struct tty_operations stl_ops
= {
3041 .put_char
= stl_putchar
,
3042 .flush_chars
= stl_flushchars
,
3043 .write_room
= stl_writeroom
,
3044 .chars_in_buffer
= stl_charsinbuffer
,
3046 .set_termios
= stl_settermios
,
3047 .throttle
= stl_throttle
,
3048 .unthrottle
= stl_unthrottle
,
3051 .hangup
= stl_hangup
,
3052 .flush_buffer
= stl_flushbuffer
,
3053 .break_ctl
= stl_breakctl
,
3054 .wait_until_sent
= stl_waituntilsent
,
3055 .send_xchar
= stl_sendxchar
,
3056 .read_proc
= stl_readproc
,
3057 .tiocmget
= stl_tiocmget
,
3058 .tiocmset
= stl_tiocmset
,
3061 /*****************************************************************************/
3063 static int __init
stl_init(void)
3066 printk(KERN_INFO
"%s: version %s\n", stl_drvtitle
, stl_drvversion
);
3070 stl_serial
= alloc_tty_driver(STL_MAXBRDS
* STL_MAXPORTS
);
3075 * Allocate a temporary write buffer.
3077 stl_tmpwritebuf
= (char *) stl_memalloc(STL_TXBUFSIZE
);
3078 if (stl_tmpwritebuf
== (char *) NULL
)
3079 printk("STALLION: failed to allocate memory (size=%d)\n",
3083 * Set up a character driver for per board stuff. This is mainly used
3084 * to do stats ioctls on the ports.
3086 if (register_chrdev(STL_SIOMEMMAJOR
, "staliomem", &stl_fsiomem
))
3087 printk("STALLION: failed to register serial board device\n");
3088 devfs_mk_dir("staliomem");
3090 stallion_class
= class_create(THIS_MODULE
, "staliomem");
3091 for (i
= 0; i
< 4; i
++) {
3092 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR
, i
),
3093 S_IFCHR
|S_IRUSR
|S_IWUSR
,
3095 class_device_create(stallion_class
, NULL
,
3096 MKDEV(STL_SIOMEMMAJOR
, i
), NULL
,
3100 stl_serial
->owner
= THIS_MODULE
;
3101 stl_serial
->driver_name
= stl_drvname
;
3102 stl_serial
->name
= "ttyE";
3103 stl_serial
->devfs_name
= "tts/E";
3104 stl_serial
->major
= STL_SERIALMAJOR
;
3105 stl_serial
->minor_start
= 0;
3106 stl_serial
->type
= TTY_DRIVER_TYPE_SERIAL
;
3107 stl_serial
->subtype
= SERIAL_TYPE_NORMAL
;
3108 stl_serial
->init_termios
= stl_deftermios
;
3109 stl_serial
->flags
= TTY_DRIVER_REAL_RAW
;
3110 tty_set_operations(stl_serial
, &stl_ops
);
3112 if (tty_register_driver(stl_serial
)) {
3113 put_tty_driver(stl_serial
);
3114 printk("STALLION: failed to register serial driver\n");
3121 /*****************************************************************************/
3122 /* CD1400 HARDWARE FUNCTIONS */
3123 /*****************************************************************************/
3126 * These functions get/set/update the registers of the cd1400 UARTs.
3127 * Access to the cd1400 registers is via an address/data io port pair.
3128 * (Maybe should make this inline...)
3131 static int stl_cd1400getreg(stlport_t
*portp
, int regnr
)
3133 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3134 return inb(portp
->ioaddr
+ EREG_DATA
);
3137 static void stl_cd1400setreg(stlport_t
*portp
, int regnr
, int value
)
3139 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3140 outb(value
, portp
->ioaddr
+ EREG_DATA
);
3143 static int stl_cd1400updatereg(stlport_t
*portp
, int regnr
, int value
)
3145 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3146 if (inb(portp
->ioaddr
+ EREG_DATA
) != value
) {
3147 outb(value
, portp
->ioaddr
+ EREG_DATA
);
3153 /*****************************************************************************/
3156 * Inbitialize the UARTs in a panel. We don't care what sort of board
3157 * these ports are on - since the port io registers are almost
3158 * identical when dealing with ports.
3161 static int stl_cd1400panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
3165 int nrchips
, uartaddr
, ioaddr
;
3168 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
3171 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
3174 * Check that each chip is present and started up OK.
3177 nrchips
= panelp
->nrports
/ CD1400_PORTS
;
3178 for (i
= 0; (i
< nrchips
); i
++) {
3179 if (brdp
->brdtype
== BRD_ECHPCI
) {
3180 outb((panelp
->pagenr
+ (i
>> 1)), brdp
->ioctrl
);
3181 ioaddr
= panelp
->iobase
;
3183 ioaddr
= panelp
->iobase
+ (EREG_BANKSIZE
* (i
>> 1));
3185 uartaddr
= (i
& 0x01) ? 0x080 : 0;
3186 outb((GFRCR
+ uartaddr
), ioaddr
);
3187 outb(0, (ioaddr
+ EREG_DATA
));
3188 outb((CCR
+ uartaddr
), ioaddr
);
3189 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
3190 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
3191 outb((GFRCR
+ uartaddr
), ioaddr
);
3192 for (j
= 0; (j
< CCR_MAXWAIT
); j
++) {
3193 if ((gfrcr
= inb(ioaddr
+ EREG_DATA
)) != 0)
3196 if ((j
>= CCR_MAXWAIT
) || (gfrcr
< 0x40) || (gfrcr
> 0x60)) {
3197 printk("STALLION: cd1400 not responding, "
3198 "brd=%d panel=%d chip=%d\n",
3199 panelp
->brdnr
, panelp
->panelnr
, i
);
3202 chipmask
|= (0x1 << i
);
3203 outb((PPR
+ uartaddr
), ioaddr
);
3204 outb(PPR_SCALAR
, (ioaddr
+ EREG_DATA
));
3207 BRDDISABLE(panelp
->brdnr
);
3211 /*****************************************************************************/
3214 * Initialize hardware specific port registers.
3217 static void stl_cd1400portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
3220 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3221 (int) brdp
, (int) panelp
, (int) portp
);
3224 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
3225 (portp
== (stlport_t
*) NULL
))
3228 portp
->ioaddr
= panelp
->iobase
+ (((brdp
->brdtype
== BRD_ECHPCI
) ||
3229 (portp
->portnr
< 8)) ? 0 : EREG_BANKSIZE
);
3230 portp
->uartaddr
= (portp
->portnr
& 0x04) << 5;
3231 portp
->pagenr
= panelp
->pagenr
+ (portp
->portnr
>> 3);
3233 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3234 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3235 stl_cd1400setreg(portp
, LIVR
, (portp
->portnr
<< 3));
3236 portp
->hwid
= stl_cd1400getreg(portp
, GFRCR
);
3237 BRDDISABLE(portp
->brdnr
);
3240 /*****************************************************************************/
3243 * Wait for the command register to be ready. We will poll this,
3244 * since it won't usually take too long to be ready.
3247 static void stl_cd1400ccrwait(stlport_t
*portp
)
3251 for (i
= 0; (i
< CCR_MAXWAIT
); i
++) {
3252 if (stl_cd1400getreg(portp
, CCR
) == 0) {
3257 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3258 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
3261 /*****************************************************************************/
3264 * Set up the cd1400 registers for a port based on the termios port
3268 static void stl_cd1400setport(stlport_t
*portp
, struct termios
*tiosp
)
3271 unsigned long flags
;
3272 unsigned int clkdiv
, baudrate
;
3273 unsigned char cor1
, cor2
, cor3
;
3274 unsigned char cor4
, cor5
, ccr
;
3275 unsigned char srer
, sreron
, sreroff
;
3276 unsigned char mcor1
, mcor2
, rtpr
;
3277 unsigned char clk
, div
;
3293 brdp
= stl_brds
[portp
->brdnr
];
3294 if (brdp
== (stlbrd_t
*) NULL
)
3298 * Set up the RX char ignore mask with those RX error types we
3299 * can ignore. We can get the cd1400 to help us out a little here,
3300 * it will ignore parity errors and breaks for us.
3302 portp
->rxignoremsk
= 0;
3303 if (tiosp
->c_iflag
& IGNPAR
) {
3304 portp
->rxignoremsk
|= (ST_PARITY
| ST_FRAMING
| ST_OVERRUN
);
3305 cor1
|= COR1_PARIGNORE
;
3307 if (tiosp
->c_iflag
& IGNBRK
) {
3308 portp
->rxignoremsk
|= ST_BREAK
;
3309 cor4
|= COR4_IGNBRK
;
3312 portp
->rxmarkmsk
= ST_OVERRUN
;
3313 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
3314 portp
->rxmarkmsk
|= (ST_PARITY
| ST_FRAMING
);
3315 if (tiosp
->c_iflag
& BRKINT
)
3316 portp
->rxmarkmsk
|= ST_BREAK
;
3319 * Go through the char size, parity and stop bits and set all the
3320 * option register appropriately.
3322 switch (tiosp
->c_cflag
& CSIZE
) {
3337 if (tiosp
->c_cflag
& CSTOPB
)
3342 if (tiosp
->c_cflag
& PARENB
) {
3343 if (tiosp
->c_cflag
& PARODD
)
3344 cor1
|= (COR1_PARENB
| COR1_PARODD
);
3346 cor1
|= (COR1_PARENB
| COR1_PAREVEN
);
3348 cor1
|= COR1_PARNONE
;
3352 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3353 * space for hardware flow control and the like. This should be set to
3354 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3355 * really be based on VTIME.
3357 cor3
|= FIFO_RXTHRESHOLD
;
3361 * Calculate the baud rate timers. For now we will just assume that
3362 * the input and output baud are the same. Could have used a baud
3363 * table here, but this way we can generate virtually any baud rate
3366 baudrate
= tiosp
->c_cflag
& CBAUD
;
3367 if (baudrate
& CBAUDEX
) {
3368 baudrate
&= ~CBAUDEX
;
3369 if ((baudrate
< 1) || (baudrate
> 4))
3370 tiosp
->c_cflag
&= ~CBAUDEX
;
3374 baudrate
= stl_baudrates
[baudrate
];
3375 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
3376 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3378 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3380 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3382 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3384 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
3385 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
3387 if (baudrate
> STL_CD1400MAXBAUD
)
3388 baudrate
= STL_CD1400MAXBAUD
;
3391 for (clk
= 0; (clk
< CD1400_NUMCLKS
); clk
++) {
3392 clkdiv
= ((portp
->clk
/ stl_cd1400clkdivs
[clk
]) / baudrate
);
3396 div
= (unsigned char) clkdiv
;
3400 * Check what form of modem signaling is required and set it up.
3402 if ((tiosp
->c_cflag
& CLOCAL
) == 0) {
3405 sreron
|= SRER_MODEM
;
3406 portp
->flags
|= ASYNC_CHECK_CD
;
3408 portp
->flags
&= ~ASYNC_CHECK_CD
;
3412 * Setup cd1400 enhanced modes if we can. In particular we want to
3413 * handle as much of the flow control as possible automatically. As
3414 * well as saving a few CPU cycles it will also greatly improve flow
3415 * control reliability.
3417 if (tiosp
->c_iflag
& IXON
) {
3420 if (tiosp
->c_iflag
& IXANY
)
3424 if (tiosp
->c_cflag
& CRTSCTS
) {
3426 mcor1
|= FIFO_RTSTHRESHOLD
;
3430 * All cd1400 register values calculated so go through and set
3435 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3436 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
3437 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3438 cor1
, cor2
, cor3
, cor4
, cor5
);
3439 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3440 mcor1
, mcor2
, rtpr
, sreron
, sreroff
);
3441 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk
, div
, clk
, div
);
3442 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3443 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
3444 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
3449 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3450 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x3));
3451 srer
= stl_cd1400getreg(portp
, SRER
);
3452 stl_cd1400setreg(portp
, SRER
, 0);
3453 if (stl_cd1400updatereg(portp
, COR1
, cor1
))
3455 if (stl_cd1400updatereg(portp
, COR2
, cor2
))
3457 if (stl_cd1400updatereg(portp
, COR3
, cor3
))
3460 stl_cd1400ccrwait(portp
);
3461 stl_cd1400setreg(portp
, CCR
, CCR_CORCHANGE
);
3463 stl_cd1400setreg(portp
, COR4
, cor4
);
3464 stl_cd1400setreg(portp
, COR5
, cor5
);
3465 stl_cd1400setreg(portp
, MCOR1
, mcor1
);
3466 stl_cd1400setreg(portp
, MCOR2
, mcor2
);
3468 stl_cd1400setreg(portp
, TCOR
, clk
);
3469 stl_cd1400setreg(portp
, TBPR
, div
);
3470 stl_cd1400setreg(portp
, RCOR
, clk
);
3471 stl_cd1400setreg(portp
, RBPR
, div
);
3473 stl_cd1400setreg(portp
, SCHR1
, tiosp
->c_cc
[VSTART
]);
3474 stl_cd1400setreg(portp
, SCHR2
, tiosp
->c_cc
[VSTOP
]);
3475 stl_cd1400setreg(portp
, SCHR3
, tiosp
->c_cc
[VSTART
]);
3476 stl_cd1400setreg(portp
, SCHR4
, tiosp
->c_cc
[VSTOP
]);
3477 stl_cd1400setreg(portp
, RTPR
, rtpr
);
3478 mcor1
= stl_cd1400getreg(portp
, MSVR1
);
3479 if (mcor1
& MSVR1_DCD
)
3480 portp
->sigs
|= TIOCM_CD
;
3482 portp
->sigs
&= ~TIOCM_CD
;
3483 stl_cd1400setreg(portp
, SRER
, ((srer
& ~sreroff
) | sreron
));
3484 BRDDISABLE(portp
->brdnr
);
3485 restore_flags(flags
);
3488 /*****************************************************************************/
3491 * Set the state of the DTR and RTS signals.
3494 static void stl_cd1400setsignals(stlport_t
*portp
, int dtr
, int rts
)
3496 unsigned char msvr1
, msvr2
;
3497 unsigned long flags
;
3500 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3501 (int) portp
, dtr
, rts
);
3513 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3514 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3516 stl_cd1400setreg(portp
, MSVR2
, msvr2
);
3518 stl_cd1400setreg(portp
, MSVR1
, msvr1
);
3519 BRDDISABLE(portp
->brdnr
);
3520 restore_flags(flags
);
3523 /*****************************************************************************/
3526 * Return the state of the signals.
3529 static int stl_cd1400getsignals(stlport_t
*portp
)
3531 unsigned char msvr1
, msvr2
;
3532 unsigned long flags
;
3536 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp
);
3541 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3542 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3543 msvr1
= stl_cd1400getreg(portp
, MSVR1
);
3544 msvr2
= stl_cd1400getreg(portp
, MSVR2
);
3545 BRDDISABLE(portp
->brdnr
);
3546 restore_flags(flags
);
3549 sigs
|= (msvr1
& MSVR1_DCD
) ? TIOCM_CD
: 0;
3550 sigs
|= (msvr1
& MSVR1_CTS
) ? TIOCM_CTS
: 0;
3551 sigs
|= (msvr1
& MSVR1_DTR
) ? TIOCM_DTR
: 0;
3552 sigs
|= (msvr2
& MSVR2_RTS
) ? TIOCM_RTS
: 0;
3554 sigs
|= (msvr1
& MSVR1_RI
) ? TIOCM_RI
: 0;
3555 sigs
|= (msvr1
& MSVR1_DSR
) ? TIOCM_DSR
: 0;
3562 /*****************************************************************************/
3565 * Enable/Disable the Transmitter and/or Receiver.
3568 static void stl_cd1400enablerxtx(stlport_t
*portp
, int rx
, int tx
)
3571 unsigned long flags
;
3574 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3575 (int) portp
, rx
, tx
);
3580 ccr
|= CCR_TXDISABLE
;
3582 ccr
|= CCR_TXENABLE
;
3584 ccr
|= CCR_RXDISABLE
;
3586 ccr
|= CCR_RXENABLE
;
3590 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3591 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3592 stl_cd1400ccrwait(portp
);
3593 stl_cd1400setreg(portp
, CCR
, ccr
);
3594 stl_cd1400ccrwait(portp
);
3595 BRDDISABLE(portp
->brdnr
);
3596 restore_flags(flags
);
3599 /*****************************************************************************/
3602 * Start/stop the Transmitter and/or Receiver.
3605 static void stl_cd1400startrxtx(stlport_t
*portp
, int rx
, int tx
)
3607 unsigned char sreron
, sreroff
;
3608 unsigned long flags
;
3611 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3612 (int) portp
, rx
, tx
);
3618 sreroff
|= (SRER_TXDATA
| SRER_TXEMPTY
);
3620 sreron
|= SRER_TXDATA
;
3622 sreron
|= SRER_TXEMPTY
;
3624 sreroff
|= SRER_RXDATA
;
3626 sreron
|= SRER_RXDATA
;
3630 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3631 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3632 stl_cd1400setreg(portp
, SRER
,
3633 ((stl_cd1400getreg(portp
, SRER
) & ~sreroff
) | sreron
));
3634 BRDDISABLE(portp
->brdnr
);
3636 set_bit(ASYI_TXBUSY
, &portp
->istate
);
3637 restore_flags(flags
);
3640 /*****************************************************************************/
3643 * Disable all interrupts from this port.
3646 static void stl_cd1400disableintrs(stlport_t
*portp
)
3648 unsigned long flags
;
3651 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp
);
3655 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3656 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3657 stl_cd1400setreg(portp
, SRER
, 0);
3658 BRDDISABLE(portp
->brdnr
);
3659 restore_flags(flags
);
3662 /*****************************************************************************/
3664 static void stl_cd1400sendbreak(stlport_t
*portp
, int len
)
3666 unsigned long flags
;
3669 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
3674 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3675 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3676 stl_cd1400setreg(portp
, SRER
,
3677 ((stl_cd1400getreg(portp
, SRER
) & ~SRER_TXDATA
) |
3679 BRDDISABLE(portp
->brdnr
);
3680 portp
->brklen
= len
;
3682 portp
->stats
.txbreaks
++;
3683 restore_flags(flags
);
3686 /*****************************************************************************/
3689 * Take flow control actions...
3692 static void stl_cd1400flowctrl(stlport_t
*portp
, int state
)
3694 struct tty_struct
*tty
;
3695 unsigned long flags
;
3698 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
3701 if (portp
== (stlport_t
*) NULL
)
3704 if (tty
== (struct tty_struct
*) NULL
)
3709 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3710 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3713 if (tty
->termios
->c_iflag
& IXOFF
) {
3714 stl_cd1400ccrwait(portp
);
3715 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3716 portp
->stats
.rxxon
++;
3717 stl_cd1400ccrwait(portp
);
3720 * Question: should we return RTS to what it was before? It may
3721 * have been set by an ioctl... Suppose not, since if you have
3722 * hardware flow control set then it is pretty silly to go and
3723 * set the RTS line by hand.
3725 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3726 stl_cd1400setreg(portp
, MCOR1
,
3727 (stl_cd1400getreg(portp
, MCOR1
) |
3728 FIFO_RTSTHRESHOLD
));
3729 stl_cd1400setreg(portp
, MSVR2
, MSVR2_RTS
);
3730 portp
->stats
.rxrtson
++;
3733 if (tty
->termios
->c_iflag
& IXOFF
) {
3734 stl_cd1400ccrwait(portp
);
3735 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3736 portp
->stats
.rxxoff
++;
3737 stl_cd1400ccrwait(portp
);
3739 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3740 stl_cd1400setreg(portp
, MCOR1
,
3741 (stl_cd1400getreg(portp
, MCOR1
) & 0xf0));
3742 stl_cd1400setreg(portp
, MSVR2
, 0);
3743 portp
->stats
.rxrtsoff
++;
3747 BRDDISABLE(portp
->brdnr
);
3748 restore_flags(flags
);
3751 /*****************************************************************************/
3754 * Send a flow control character...
3757 static void stl_cd1400sendflow(stlport_t
*portp
, int state
)
3759 struct tty_struct
*tty
;
3760 unsigned long flags
;
3763 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
3766 if (portp
== (stlport_t
*) NULL
)
3769 if (tty
== (struct tty_struct
*) NULL
)
3774 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3775 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3777 stl_cd1400ccrwait(portp
);
3778 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3779 portp
->stats
.rxxon
++;
3780 stl_cd1400ccrwait(portp
);
3782 stl_cd1400ccrwait(portp
);
3783 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3784 portp
->stats
.rxxoff
++;
3785 stl_cd1400ccrwait(portp
);
3787 BRDDISABLE(portp
->brdnr
);
3788 restore_flags(flags
);
3791 /*****************************************************************************/
3793 static void stl_cd1400flush(stlport_t
*portp
)
3795 unsigned long flags
;
3798 printk("stl_cd1400flush(portp=%x)\n", (int) portp
);
3801 if (portp
== (stlport_t
*) NULL
)
3806 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3807 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3808 stl_cd1400ccrwait(portp
);
3809 stl_cd1400setreg(portp
, CCR
, CCR_TXFLUSHFIFO
);
3810 stl_cd1400ccrwait(portp
);
3811 portp
->tx
.tail
= portp
->tx
.head
;
3812 BRDDISABLE(portp
->brdnr
);
3813 restore_flags(flags
);
3816 /*****************************************************************************/
3819 * Return the current state of data flow on this port. This is only
3820 * really interresting when determining if data has fully completed
3821 * transmission or not... This is easy for the cd1400, it accurately
3822 * maintains the busy port flag.
3825 static int stl_cd1400datastate(stlport_t
*portp
)
3828 printk("stl_cd1400datastate(portp=%x)\n", (int) portp
);
3831 if (portp
== (stlport_t
*) NULL
)
3834 return test_bit(ASYI_TXBUSY
, &portp
->istate
) ? 1 : 0;
3837 /*****************************************************************************/
3840 * Interrupt service routine for cd1400 EasyIO boards.
3843 static void stl_cd1400eiointr(stlpanel_t
*panelp
, unsigned int iobase
)
3845 unsigned char svrtype
;
3848 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3849 (int) panelp
, iobase
);
3853 svrtype
= inb(iobase
+ EREG_DATA
);
3854 if (panelp
->nrports
> 4) {
3855 outb((SVRR
+ 0x80), iobase
);
3856 svrtype
|= inb(iobase
+ EREG_DATA
);
3859 if (svrtype
& SVRR_RX
)
3860 stl_cd1400rxisr(panelp
, iobase
);
3861 else if (svrtype
& SVRR_TX
)
3862 stl_cd1400txisr(panelp
, iobase
);
3863 else if (svrtype
& SVRR_MDM
)
3864 stl_cd1400mdmisr(panelp
, iobase
);
3867 /*****************************************************************************/
3870 * Interrupt service routine for cd1400 panels.
3873 static void stl_cd1400echintr(stlpanel_t
*panelp
, unsigned int iobase
)
3875 unsigned char svrtype
;
3878 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp
,
3883 svrtype
= inb(iobase
+ EREG_DATA
);
3884 outb((SVRR
+ 0x80), iobase
);
3885 svrtype
|= inb(iobase
+ EREG_DATA
);
3886 if (svrtype
& SVRR_RX
)
3887 stl_cd1400rxisr(panelp
, iobase
);
3888 else if (svrtype
& SVRR_TX
)
3889 stl_cd1400txisr(panelp
, iobase
);
3890 else if (svrtype
& SVRR_MDM
)
3891 stl_cd1400mdmisr(panelp
, iobase
);
3895 /*****************************************************************************/
3898 * Unfortunately we need to handle breaks in the TX data stream, since
3899 * this is the only way to generate them on the cd1400.
3902 static inline int stl_cd1400breakisr(stlport_t
*portp
, int ioaddr
)
3904 if (portp
->brklen
== 1) {
3905 outb((COR2
+ portp
->uartaddr
), ioaddr
);
3906 outb((inb(ioaddr
+ EREG_DATA
) | COR2_ETC
),
3907 (ioaddr
+ EREG_DATA
));
3908 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3909 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
3910 outb(ETC_STARTBREAK
, (ioaddr
+ EREG_DATA
));
3911 outb((SRER
+ portp
->uartaddr
), ioaddr
);
3912 outb((inb(ioaddr
+ EREG_DATA
) & ~(SRER_TXDATA
| SRER_TXEMPTY
)),
3913 (ioaddr
+ EREG_DATA
));
3915 } else if (portp
->brklen
> 1) {
3916 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3917 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
3918 outb(ETC_STOPBREAK
, (ioaddr
+ EREG_DATA
));
3922 outb((COR2
+ portp
->uartaddr
), ioaddr
);
3923 outb((inb(ioaddr
+ EREG_DATA
) & ~COR2_ETC
),
3924 (ioaddr
+ EREG_DATA
));
3930 /*****************************************************************************/
3933 * Transmit interrupt handler. This has gotta be fast! Handling TX
3934 * chars is pretty simple, stuff as many as possible from the TX buffer
3935 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3936 * are embedded as commands in the data stream. Oh no, had to use a goto!
3937 * This could be optimized more, will do when I get time...
3938 * In practice it is possible that interrupts are enabled but that the
3939 * port has been hung up. Need to handle not having any TX buffer here,
3940 * this is done by using the side effect that head and tail will also
3941 * be NULL if the buffer has been freed.
3944 static void stl_cd1400txisr(stlpanel_t
*panelp
, int ioaddr
)
3949 unsigned char ioack
, srer
;
3952 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
3955 ioack
= inb(ioaddr
+ EREG_TXACK
);
3956 if (((ioack
& panelp
->ackmask
) != 0) ||
3957 ((ioack
& ACK_TYPMASK
) != ACK_TYPTX
)) {
3958 printk("STALLION: bad TX interrupt ack value=%x\n", ioack
);
3961 portp
= panelp
->ports
[(ioack
>> 3)];
3964 * Unfortunately we need to handle breaks in the data stream, since
3965 * this is the only way to generate them on the cd1400. Do it now if
3966 * a break is to be sent.
3968 if (portp
->brklen
!= 0)
3969 if (stl_cd1400breakisr(portp
, ioaddr
))
3972 head
= portp
->tx
.head
;
3973 tail
= portp
->tx
.tail
;
3974 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
3975 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
3976 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
3977 set_bit(ASYI_TXLOW
, &portp
->istate
);
3978 schedule_work(&portp
->tqueue
);
3982 outb((SRER
+ portp
->uartaddr
), ioaddr
);
3983 srer
= inb(ioaddr
+ EREG_DATA
);
3984 if (srer
& SRER_TXDATA
) {
3985 srer
= (srer
& ~SRER_TXDATA
) | SRER_TXEMPTY
;
3987 srer
&= ~(SRER_TXDATA
| SRER_TXEMPTY
);
3988 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
3990 outb(srer
, (ioaddr
+ EREG_DATA
));
3992 len
= MIN(len
, CD1400_TXFIFOSIZE
);
3993 portp
->stats
.txtotal
+= len
;
3994 stlen
= MIN(len
, ((portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
));
3995 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3996 outsb((ioaddr
+ EREG_DATA
), tail
, stlen
);
3999 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
4000 tail
= portp
->tx
.buf
;
4002 outsb((ioaddr
+ EREG_DATA
), tail
, len
);
4005 portp
->tx
.tail
= tail
;
4009 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4010 outb(0, (ioaddr
+ EREG_DATA
));
4013 /*****************************************************************************/
4016 * Receive character interrupt handler. Determine if we have good chars
4017 * or bad chars and then process appropriately. Good chars are easy
4018 * just shove the lot into the RX buffer and set all status byte to 0.
4019 * If a bad RX char then process as required. This routine needs to be
4020 * fast! In practice it is possible that we get an interrupt on a port
4021 * that is closed. This can happen on hangups - since they completely
4022 * shutdown a port not in user context. Need to handle this case.
4025 static void stl_cd1400rxisr(stlpanel_t
*panelp
, int ioaddr
)
4028 struct tty_struct
*tty
;
4029 unsigned int ioack
, len
, buflen
;
4030 unsigned char status
;
4034 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
4037 ioack
= inb(ioaddr
+ EREG_RXACK
);
4038 if ((ioack
& panelp
->ackmask
) != 0) {
4039 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
4042 portp
= panelp
->ports
[(ioack
>> 3)];
4045 if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXGOOD
) {
4046 outb((RDCR
+ portp
->uartaddr
), ioaddr
);
4047 len
= inb(ioaddr
+ EREG_DATA
);
4048 if (tty
== NULL
|| (buflen
= tty_buffer_request_room(tty
, len
)) == 0) {
4049 len
= MIN(len
, sizeof(stl_unwanted
));
4050 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4051 insb((ioaddr
+ EREG_DATA
), &stl_unwanted
[0], len
);
4052 portp
->stats
.rxlost
+= len
;
4053 portp
->stats
.rxtotal
+= len
;
4055 len
= MIN(len
, buflen
);
4058 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4059 tty_prepare_flip_string(tty
, &ptr
, len
);
4060 insb((ioaddr
+ EREG_DATA
), ptr
, len
);
4061 tty_schedule_flip(tty
);
4062 portp
->stats
.rxtotal
+= len
;
4065 } else if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXBAD
) {
4066 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4067 status
= inb(ioaddr
+ EREG_DATA
);
4068 ch
= inb(ioaddr
+ EREG_DATA
);
4069 if (status
& ST_PARITY
)
4070 portp
->stats
.rxparity
++;
4071 if (status
& ST_FRAMING
)
4072 portp
->stats
.rxframing
++;
4073 if (status
& ST_OVERRUN
)
4074 portp
->stats
.rxoverrun
++;
4075 if (status
& ST_BREAK
)
4076 portp
->stats
.rxbreaks
++;
4077 if (status
& ST_SCHARMASK
) {
4078 if ((status
& ST_SCHARMASK
) == ST_SCHAR1
)
4079 portp
->stats
.txxon
++;
4080 if ((status
& ST_SCHARMASK
) == ST_SCHAR2
)
4081 portp
->stats
.txxoff
++;
4084 if (tty
!= NULL
&& (portp
->rxignoremsk
& status
) == 0) {
4085 if (portp
->rxmarkmsk
& status
) {
4086 if (status
& ST_BREAK
) {
4088 if (portp
->flags
& ASYNC_SAK
) {
4090 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4092 } else if (status
& ST_PARITY
) {
4093 status
= TTY_PARITY
;
4094 } else if (status
& ST_FRAMING
) {
4096 } else if(status
& ST_OVERRUN
) {
4097 status
= TTY_OVERRUN
;
4104 tty_insert_flip_char(tty
, ch
, status
);
4105 tty_schedule_flip(tty
);
4108 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
4113 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4114 outb(0, (ioaddr
+ EREG_DATA
));
4117 /*****************************************************************************/
4120 * Modem interrupt handler. The is called when the modem signal line
4121 * (DCD) has changed state. Leave most of the work to the off-level
4122 * processing routine.
4125 static void stl_cd1400mdmisr(stlpanel_t
*panelp
, int ioaddr
)
4132 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp
);
4135 ioack
= inb(ioaddr
+ EREG_MDACK
);
4136 if (((ioack
& panelp
->ackmask
) != 0) ||
4137 ((ioack
& ACK_TYPMASK
) != ACK_TYPMDM
)) {
4138 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack
);
4141 portp
= panelp
->ports
[(ioack
>> 3)];
4143 outb((MISR
+ portp
->uartaddr
), ioaddr
);
4144 misr
= inb(ioaddr
+ EREG_DATA
);
4145 if (misr
& MISR_DCD
) {
4146 set_bit(ASYI_DCDCHANGE
, &portp
->istate
);
4147 schedule_work(&portp
->tqueue
);
4148 portp
->stats
.modem
++;
4151 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4152 outb(0, (ioaddr
+ EREG_DATA
));
4155 /*****************************************************************************/
4156 /* SC26198 HARDWARE FUNCTIONS */
4157 /*****************************************************************************/
4160 * These functions get/set/update the registers of the sc26198 UARTs.
4161 * Access to the sc26198 registers is via an address/data io port pair.
4162 * (Maybe should make this inline...)
4165 static int stl_sc26198getreg(stlport_t
*portp
, int regnr
)
4167 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4168 return inb(portp
->ioaddr
+ XP_DATA
);
4171 static void stl_sc26198setreg(stlport_t
*portp
, int regnr
, int value
)
4173 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4174 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4177 static int stl_sc26198updatereg(stlport_t
*portp
, int regnr
, int value
)
4179 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4180 if (inb(portp
->ioaddr
+ XP_DATA
) != value
) {
4181 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4187 /*****************************************************************************/
4190 * Functions to get and set the sc26198 global registers.
4193 static int stl_sc26198getglobreg(stlport_t
*portp
, int regnr
)
4195 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
4196 return inb(portp
->ioaddr
+ XP_DATA
);
4200 static void stl_sc26198setglobreg(stlport_t
*portp
, int regnr
, int value
)
4202 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
4203 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4207 /*****************************************************************************/
4210 * Inbitialize the UARTs in a panel. We don't care what sort of board
4211 * these ports are on - since the port io registers are almost
4212 * identical when dealing with ports.
4215 static int stl_sc26198panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
4218 int nrchips
, ioaddr
;
4221 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4222 (int) brdp
, (int) panelp
);
4225 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
4228 * Check that each chip is present and started up OK.
4231 nrchips
= (panelp
->nrports
+ 4) / SC26198_PORTS
;
4232 if (brdp
->brdtype
== BRD_ECHPCI
)
4233 outb(panelp
->pagenr
, brdp
->ioctrl
);
4235 for (i
= 0; (i
< nrchips
); i
++) {
4236 ioaddr
= panelp
->iobase
+ (i
* 4);
4237 outb(SCCR
, (ioaddr
+ XP_ADDR
));
4238 outb(CR_RESETALL
, (ioaddr
+ XP_DATA
));
4239 outb(TSTR
, (ioaddr
+ XP_ADDR
));
4240 if (inb(ioaddr
+ XP_DATA
) != 0) {
4241 printk("STALLION: sc26198 not responding, "
4242 "brd=%d panel=%d chip=%d\n",
4243 panelp
->brdnr
, panelp
->panelnr
, i
);
4246 chipmask
|= (0x1 << i
);
4247 outb(GCCR
, (ioaddr
+ XP_ADDR
));
4248 outb(GCCR_IVRTYPCHANACK
, (ioaddr
+ XP_DATA
));
4249 outb(WDTRCR
, (ioaddr
+ XP_ADDR
));
4250 outb(0xff, (ioaddr
+ XP_DATA
));
4253 BRDDISABLE(panelp
->brdnr
);
4257 /*****************************************************************************/
4260 * Initialize hardware specific port registers.
4263 static void stl_sc26198portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
4266 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4267 (int) brdp
, (int) panelp
, (int) portp
);
4270 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
4271 (portp
== (stlport_t
*) NULL
))
4274 portp
->ioaddr
= panelp
->iobase
+ ((portp
->portnr
< 8) ? 0 : 4);
4275 portp
->uartaddr
= (portp
->portnr
& 0x07) << 4;
4276 portp
->pagenr
= panelp
->pagenr
;
4279 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4280 stl_sc26198setreg(portp
, IOPCR
, IOPCR_SETSIGS
);
4281 BRDDISABLE(portp
->brdnr
);
4284 /*****************************************************************************/
4287 * Set up the sc26198 registers for a port based on the termios port
4291 static void stl_sc26198setport(stlport_t
*portp
, struct termios
*tiosp
)
4294 unsigned long flags
;
4295 unsigned int baudrate
;
4296 unsigned char mr0
, mr1
, mr2
, clk
;
4297 unsigned char imron
, imroff
, iopr
, ipr
;
4307 brdp
= stl_brds
[portp
->brdnr
];
4308 if (brdp
== (stlbrd_t
*) NULL
)
4312 * Set up the RX char ignore mask with those RX error types we
4315 portp
->rxignoremsk
= 0;
4316 if (tiosp
->c_iflag
& IGNPAR
)
4317 portp
->rxignoremsk
|= (SR_RXPARITY
| SR_RXFRAMING
|
4319 if (tiosp
->c_iflag
& IGNBRK
)
4320 portp
->rxignoremsk
|= SR_RXBREAK
;
4322 portp
->rxmarkmsk
= SR_RXOVERRUN
;
4323 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
4324 portp
->rxmarkmsk
|= (SR_RXPARITY
| SR_RXFRAMING
);
4325 if (tiosp
->c_iflag
& BRKINT
)
4326 portp
->rxmarkmsk
|= SR_RXBREAK
;
4329 * Go through the char size, parity and stop bits and set all the
4330 * option register appropriately.
4332 switch (tiosp
->c_cflag
& CSIZE
) {
4347 if (tiosp
->c_cflag
& CSTOPB
)
4352 if (tiosp
->c_cflag
& PARENB
) {
4353 if (tiosp
->c_cflag
& PARODD
)
4354 mr1
|= (MR1_PARENB
| MR1_PARODD
);
4356 mr1
|= (MR1_PARENB
| MR1_PAREVEN
);
4361 mr1
|= MR1_ERRBLOCK
;
4364 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4365 * space for hardware flow control and the like. This should be set to
4368 mr2
|= MR2_RXFIFOHALF
;
4371 * Calculate the baud rate timers. For now we will just assume that
4372 * the input and output baud are the same. The sc26198 has a fixed
4373 * baud rate table, so only discrete baud rates possible.
4375 baudrate
= tiosp
->c_cflag
& CBAUD
;
4376 if (baudrate
& CBAUDEX
) {
4377 baudrate
&= ~CBAUDEX
;
4378 if ((baudrate
< 1) || (baudrate
> 4))
4379 tiosp
->c_cflag
&= ~CBAUDEX
;
4383 baudrate
= stl_baudrates
[baudrate
];
4384 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
4385 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
4387 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
4389 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
4391 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
4393 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
4394 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
4396 if (baudrate
> STL_SC26198MAXBAUD
)
4397 baudrate
= STL_SC26198MAXBAUD
;
4400 for (clk
= 0; (clk
< SC26198_NRBAUDS
); clk
++) {
4401 if (baudrate
<= sc26198_baudtable
[clk
])
4407 * Check what form of modem signaling is required and set it up.
4409 if (tiosp
->c_cflag
& CLOCAL
) {
4410 portp
->flags
&= ~ASYNC_CHECK_CD
;
4412 iopr
|= IOPR_DCDCOS
;
4414 portp
->flags
|= ASYNC_CHECK_CD
;
4418 * Setup sc26198 enhanced modes if we can. In particular we want to
4419 * handle as much of the flow control as possible automatically. As
4420 * well as saving a few CPU cycles it will also greatly improve flow
4421 * control reliability.
4423 if (tiosp
->c_iflag
& IXON
) {
4424 mr0
|= MR0_SWFTX
| MR0_SWFT
;
4425 imron
|= IR_XONXOFF
;
4427 imroff
|= IR_XONXOFF
;
4429 if (tiosp
->c_iflag
& IXOFF
)
4432 if (tiosp
->c_cflag
& CRTSCTS
) {
4438 * All sc26198 register values calculated so go through and set
4443 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4444 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
4445 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0
, mr1
, mr2
, clk
);
4446 printk(" iopr=%x imron=%x imroff=%x\n", iopr
, imron
, imroff
);
4447 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4448 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
4449 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
4454 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4455 stl_sc26198setreg(portp
, IMR
, 0);
4456 stl_sc26198updatereg(portp
, MR0
, mr0
);
4457 stl_sc26198updatereg(portp
, MR1
, mr1
);
4458 stl_sc26198setreg(portp
, SCCR
, CR_RXERRBLOCK
);
4459 stl_sc26198updatereg(portp
, MR2
, mr2
);
4460 stl_sc26198updatereg(portp
, IOPIOR
,
4461 ((stl_sc26198getreg(portp
, IOPIOR
) & ~IPR_CHANGEMASK
) | iopr
));
4464 stl_sc26198setreg(portp
, TXCSR
, clk
);
4465 stl_sc26198setreg(portp
, RXCSR
, clk
);
4468 stl_sc26198setreg(portp
, XONCR
, tiosp
->c_cc
[VSTART
]);
4469 stl_sc26198setreg(portp
, XOFFCR
, tiosp
->c_cc
[VSTOP
]);
4471 ipr
= stl_sc26198getreg(portp
, IPR
);
4473 portp
->sigs
&= ~TIOCM_CD
;
4475 portp
->sigs
|= TIOCM_CD
;
4477 portp
->imr
= (portp
->imr
& ~imroff
) | imron
;
4478 stl_sc26198setreg(portp
, IMR
, portp
->imr
);
4479 BRDDISABLE(portp
->brdnr
);
4480 restore_flags(flags
);
4483 /*****************************************************************************/
4486 * Set the state of the DTR and RTS signals.
4489 static void stl_sc26198setsignals(stlport_t
*portp
, int dtr
, int rts
)
4491 unsigned char iopioron
, iopioroff
;
4492 unsigned long flags
;
4495 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4496 (int) portp
, dtr
, rts
);
4502 iopioroff
|= IPR_DTR
;
4504 iopioron
|= IPR_DTR
;
4506 iopioroff
|= IPR_RTS
;
4508 iopioron
|= IPR_RTS
;
4512 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4513 stl_sc26198setreg(portp
, IOPIOR
,
4514 ((stl_sc26198getreg(portp
, IOPIOR
) & ~iopioroff
) | iopioron
));
4515 BRDDISABLE(portp
->brdnr
);
4516 restore_flags(flags
);
4519 /*****************************************************************************/
4522 * Return the state of the signals.
4525 static int stl_sc26198getsignals(stlport_t
*portp
)
4528 unsigned long flags
;
4532 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp
);
4537 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4538 ipr
= stl_sc26198getreg(portp
, IPR
);
4539 BRDDISABLE(portp
->brdnr
);
4540 restore_flags(flags
);
4543 sigs
|= (ipr
& IPR_DCD
) ? 0 : TIOCM_CD
;
4544 sigs
|= (ipr
& IPR_CTS
) ? 0 : TIOCM_CTS
;
4545 sigs
|= (ipr
& IPR_DTR
) ? 0: TIOCM_DTR
;
4546 sigs
|= (ipr
& IPR_RTS
) ? 0: TIOCM_RTS
;
4551 /*****************************************************************************/
4554 * Enable/Disable the Transmitter and/or Receiver.
4557 static void stl_sc26198enablerxtx(stlport_t
*portp
, int rx
, int tx
)
4560 unsigned long flags
;
4563 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4564 (int) portp
, rx
, tx
);
4567 ccr
= portp
->crenable
;
4569 ccr
&= ~CR_TXENABLE
;
4573 ccr
&= ~CR_RXENABLE
;
4579 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4580 stl_sc26198setreg(portp
, SCCR
, ccr
);
4581 BRDDISABLE(portp
->brdnr
);
4582 portp
->crenable
= ccr
;
4583 restore_flags(flags
);
4586 /*****************************************************************************/
4589 * Start/stop the Transmitter and/or Receiver.
4592 static void stl_sc26198startrxtx(stlport_t
*portp
, int rx
, int tx
)
4595 unsigned long flags
;
4598 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4599 (int) portp
, rx
, tx
);
4608 imr
&= ~(IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
);
4610 imr
|= IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
;
4614 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4615 stl_sc26198setreg(portp
, IMR
, imr
);
4616 BRDDISABLE(portp
->brdnr
);
4619 set_bit(ASYI_TXBUSY
, &portp
->istate
);
4620 restore_flags(flags
);
4623 /*****************************************************************************/
4626 * Disable all interrupts from this port.
4629 static void stl_sc26198disableintrs(stlport_t
*portp
)
4631 unsigned long flags
;
4634 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp
);
4639 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4641 stl_sc26198setreg(portp
, IMR
, 0);
4642 BRDDISABLE(portp
->brdnr
);
4643 restore_flags(flags
);
4646 /*****************************************************************************/
4648 static void stl_sc26198sendbreak(stlport_t
*portp
, int len
)
4650 unsigned long flags
;
4653 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
4658 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4660 stl_sc26198setreg(portp
, SCCR
, CR_TXSTARTBREAK
);
4661 portp
->stats
.txbreaks
++;
4663 stl_sc26198setreg(portp
, SCCR
, CR_TXSTOPBREAK
);
4665 BRDDISABLE(portp
->brdnr
);
4666 restore_flags(flags
);
4669 /*****************************************************************************/
4672 * Take flow control actions...
4675 static void stl_sc26198flowctrl(stlport_t
*portp
, int state
)
4677 struct tty_struct
*tty
;
4678 unsigned long flags
;
4682 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
4685 if (portp
== (stlport_t
*) NULL
)
4688 if (tty
== (struct tty_struct
*) NULL
)
4693 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4696 if (tty
->termios
->c_iflag
& IXOFF
) {
4697 mr0
= stl_sc26198getreg(portp
, MR0
);
4698 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4699 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4701 portp
->stats
.rxxon
++;
4702 stl_sc26198wait(portp
);
4703 stl_sc26198setreg(portp
, MR0
, mr0
);
4706 * Question: should we return RTS to what it was before? It may
4707 * have been set by an ioctl... Suppose not, since if you have
4708 * hardware flow control set then it is pretty silly to go and
4709 * set the RTS line by hand.
4711 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4712 stl_sc26198setreg(portp
, MR1
,
4713 (stl_sc26198getreg(portp
, MR1
) | MR1_AUTORTS
));
4714 stl_sc26198setreg(portp
, IOPIOR
,
4715 (stl_sc26198getreg(portp
, IOPIOR
) | IOPR_RTS
));
4716 portp
->stats
.rxrtson
++;
4719 if (tty
->termios
->c_iflag
& IXOFF
) {
4720 mr0
= stl_sc26198getreg(portp
, MR0
);
4721 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4722 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4724 portp
->stats
.rxxoff
++;
4725 stl_sc26198wait(portp
);
4726 stl_sc26198setreg(portp
, MR0
, mr0
);
4728 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4729 stl_sc26198setreg(portp
, MR1
,
4730 (stl_sc26198getreg(portp
, MR1
) & ~MR1_AUTORTS
));
4731 stl_sc26198setreg(portp
, IOPIOR
,
4732 (stl_sc26198getreg(portp
, IOPIOR
) & ~IOPR_RTS
));
4733 portp
->stats
.rxrtsoff
++;
4737 BRDDISABLE(portp
->brdnr
);
4738 restore_flags(flags
);
4741 /*****************************************************************************/
4744 * Send a flow control character.
4747 static void stl_sc26198sendflow(stlport_t
*portp
, int state
)
4749 struct tty_struct
*tty
;
4750 unsigned long flags
;
4754 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
4757 if (portp
== (stlport_t
*) NULL
)
4760 if (tty
== (struct tty_struct
*) NULL
)
4765 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4767 mr0
= stl_sc26198getreg(portp
, MR0
);
4768 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4769 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4771 portp
->stats
.rxxon
++;
4772 stl_sc26198wait(portp
);
4773 stl_sc26198setreg(portp
, MR0
, mr0
);
4775 mr0
= stl_sc26198getreg(portp
, MR0
);
4776 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4777 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4779 portp
->stats
.rxxoff
++;
4780 stl_sc26198wait(portp
);
4781 stl_sc26198setreg(portp
, MR0
, mr0
);
4783 BRDDISABLE(portp
->brdnr
);
4784 restore_flags(flags
);
4787 /*****************************************************************************/
4789 static void stl_sc26198flush(stlport_t
*portp
)
4791 unsigned long flags
;
4794 printk("stl_sc26198flush(portp=%x)\n", (int) portp
);
4797 if (portp
== (stlport_t
*) NULL
)
4802 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4803 stl_sc26198setreg(portp
, SCCR
, CR_TXRESET
);
4804 stl_sc26198setreg(portp
, SCCR
, portp
->crenable
);
4805 BRDDISABLE(portp
->brdnr
);
4806 portp
->tx
.tail
= portp
->tx
.head
;
4807 restore_flags(flags
);
4810 /*****************************************************************************/
4813 * Return the current state of data flow on this port. This is only
4814 * really interresting when determining if data has fully completed
4815 * transmission or not... The sc26198 interrupt scheme cannot
4816 * determine when all data has actually drained, so we need to
4817 * check the port statusy register to be sure.
4820 static int stl_sc26198datastate(stlport_t
*portp
)
4822 unsigned long flags
;
4826 printk("stl_sc26198datastate(portp=%x)\n", (int) portp
);
4829 if (portp
== (stlport_t
*) NULL
)
4831 if (test_bit(ASYI_TXBUSY
, &portp
->istate
))
4836 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4837 sr
= stl_sc26198getreg(portp
, SR
);
4838 BRDDISABLE(portp
->brdnr
);
4839 restore_flags(flags
);
4841 return (sr
& SR_TXEMPTY
) ? 0 : 1;
4844 /*****************************************************************************/
4847 * Delay for a small amount of time, to give the sc26198 a chance
4848 * to process a command...
4851 static void stl_sc26198wait(stlport_t
*portp
)
4856 printk("stl_sc26198wait(portp=%x)\n", (int) portp
);
4859 if (portp
== (stlport_t
*) NULL
)
4862 for (i
= 0; (i
< 20); i
++)
4863 stl_sc26198getglobreg(portp
, TSTR
);
4866 /*****************************************************************************/
4869 * If we are TX flow controlled and in IXANY mode then we may
4870 * need to unflow control here. We gotta do this because of the
4871 * automatic flow control modes of the sc26198.
4874 static inline void stl_sc26198txunflow(stlport_t
*portp
, struct tty_struct
*tty
)
4878 mr0
= stl_sc26198getreg(portp
, MR0
);
4879 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4880 stl_sc26198setreg(portp
, SCCR
, CR_HOSTXON
);
4881 stl_sc26198wait(portp
);
4882 stl_sc26198setreg(portp
, MR0
, mr0
);
4883 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
4886 /*****************************************************************************/
4889 * Interrupt service routine for sc26198 panels.
4892 static void stl_sc26198intr(stlpanel_t
*panelp
, unsigned int iobase
)
4898 * Work around bug in sc26198 chip... Cannot have A6 address
4899 * line of UART high, else iack will be returned as 0.
4901 outb(0, (iobase
+ 1));
4903 iack
= inb(iobase
+ XP_IACK
);
4904 portp
= panelp
->ports
[(iack
& IVR_CHANMASK
) + ((iobase
& 0x4) << 1)];
4906 if (iack
& IVR_RXDATA
)
4907 stl_sc26198rxisr(portp
, iack
);
4908 else if (iack
& IVR_TXDATA
)
4909 stl_sc26198txisr(portp
);
4911 stl_sc26198otherisr(portp
, iack
);
4914 /*****************************************************************************/
4917 * Transmit interrupt handler. This has gotta be fast! Handling TX
4918 * chars is pretty simple, stuff as many as possible from the TX buffer
4919 * into the sc26198 FIFO.
4920 * In practice it is possible that interrupts are enabled but that the
4921 * port has been hung up. Need to handle not having any TX buffer here,
4922 * this is done by using the side effect that head and tail will also
4923 * be NULL if the buffer has been freed.
4926 static void stl_sc26198txisr(stlport_t
*portp
)
4928 unsigned int ioaddr
;
4934 printk("stl_sc26198txisr(portp=%x)\n", (int) portp
);
4937 ioaddr
= portp
->ioaddr
;
4938 head
= portp
->tx
.head
;
4939 tail
= portp
->tx
.tail
;
4940 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
4941 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
4942 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
4943 set_bit(ASYI_TXLOW
, &portp
->istate
);
4944 schedule_work(&portp
->tqueue
);
4948 outb((MR0
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
4949 mr0
= inb(ioaddr
+ XP_DATA
);
4950 if ((mr0
& MR0_TXMASK
) == MR0_TXEMPTY
) {
4951 portp
->imr
&= ~IR_TXRDY
;
4952 outb((IMR
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
4953 outb(portp
->imr
, (ioaddr
+ XP_DATA
));
4954 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
4956 mr0
|= ((mr0
& ~MR0_TXMASK
) | MR0_TXEMPTY
);
4957 outb(mr0
, (ioaddr
+ XP_DATA
));
4960 len
= MIN(len
, SC26198_TXFIFOSIZE
);
4961 portp
->stats
.txtotal
+= len
;
4962 stlen
= MIN(len
, ((portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
));
4963 outb(GTXFIFO
, (ioaddr
+ XP_ADDR
));
4964 outsb((ioaddr
+ XP_DATA
), tail
, stlen
);
4967 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
4968 tail
= portp
->tx
.buf
;
4970 outsb((ioaddr
+ XP_DATA
), tail
, len
);
4973 portp
->tx
.tail
= tail
;
4977 /*****************************************************************************/
4980 * Receive character interrupt handler. Determine if we have good chars
4981 * or bad chars and then process appropriately. Good chars are easy
4982 * just shove the lot into the RX buffer and set all status byte to 0.
4983 * If a bad RX char then process as required. This routine needs to be
4984 * fast! In practice it is possible that we get an interrupt on a port
4985 * that is closed. This can happen on hangups - since they completely
4986 * shutdown a port not in user context. Need to handle this case.
4989 static void stl_sc26198rxisr(stlport_t
*portp
, unsigned int iack
)
4991 struct tty_struct
*tty
;
4992 unsigned int len
, buflen
, ioaddr
;
4995 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
4999 ioaddr
= portp
->ioaddr
;
5000 outb(GIBCR
, (ioaddr
+ XP_ADDR
));
5001 len
= inb(ioaddr
+ XP_DATA
) + 1;
5003 if ((iack
& IVR_TYPEMASK
) == IVR_RXDATA
) {
5004 if (tty
== NULL
|| (buflen
= tty_buffer_request_room(tty
, len
)) == 0) {
5005 len
= MIN(len
, sizeof(stl_unwanted
));
5006 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
5007 insb((ioaddr
+ XP_DATA
), &stl_unwanted
[0], len
);
5008 portp
->stats
.rxlost
+= len
;
5009 portp
->stats
.rxtotal
+= len
;
5011 len
= MIN(len
, buflen
);
5014 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
5015 tty_prepare_flip_string(tty
, &ptr
, len
);
5016 insb((ioaddr
+ XP_DATA
), ptr
, len
);
5017 tty_schedule_flip(tty
);
5018 portp
->stats
.rxtotal
+= len
;
5022 stl_sc26198rxbadchars(portp
);
5026 * If we are TX flow controlled and in IXANY mode then we may need
5027 * to unflow control here. We gotta do this because of the automatic
5028 * flow control modes of the sc26198.
5030 if (test_bit(ASYI_TXFLOWED
, &portp
->istate
)) {
5031 if ((tty
!= (struct tty_struct
*) NULL
) &&
5032 (tty
->termios
!= (struct termios
*) NULL
) &&
5033 (tty
->termios
->c_iflag
& IXANY
)) {
5034 stl_sc26198txunflow(portp
, tty
);
5039 /*****************************************************************************/
5042 * Process an RX bad character.
5045 static inline void stl_sc26198rxbadch(stlport_t
*portp
, unsigned char status
, char ch
)
5047 struct tty_struct
*tty
;
5048 unsigned int ioaddr
;
5051 ioaddr
= portp
->ioaddr
;
5053 if (status
& SR_RXPARITY
)
5054 portp
->stats
.rxparity
++;
5055 if (status
& SR_RXFRAMING
)
5056 portp
->stats
.rxframing
++;
5057 if (status
& SR_RXOVERRUN
)
5058 portp
->stats
.rxoverrun
++;
5059 if (status
& SR_RXBREAK
)
5060 portp
->stats
.rxbreaks
++;
5062 if ((tty
!= (struct tty_struct
*) NULL
) &&
5063 ((portp
->rxignoremsk
& status
) == 0)) {
5064 if (portp
->rxmarkmsk
& status
) {
5065 if (status
& SR_RXBREAK
) {
5067 if (portp
->flags
& ASYNC_SAK
) {
5069 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
5071 } else if (status
& SR_RXPARITY
) {
5072 status
= TTY_PARITY
;
5073 } else if (status
& SR_RXFRAMING
) {
5075 } else if(status
& SR_RXOVERRUN
) {
5076 status
= TTY_OVERRUN
;
5084 tty_insert_flip_char(tty
, ch
, status
);
5085 tty_schedule_flip(tty
);
5088 portp
->stats
.rxtotal
++;
5092 /*****************************************************************************/
5095 * Process all characters in the RX FIFO of the UART. Check all char
5096 * status bytes as well, and process as required. We need to check
5097 * all bytes in the FIFO, in case some more enter the FIFO while we
5098 * are here. To get the exact character error type we need to switch
5099 * into CHAR error mode (that is why we need to make sure we empty
5103 static void stl_sc26198rxbadchars(stlport_t
*portp
)
5105 unsigned char status
, mr1
;
5109 * To get the precise error type for each character we must switch
5110 * back into CHAR error mode.
5112 mr1
= stl_sc26198getreg(portp
, MR1
);
5113 stl_sc26198setreg(portp
, MR1
, (mr1
& ~MR1_ERRBLOCK
));
5115 while ((status
= stl_sc26198getreg(portp
, SR
)) & SR_RXRDY
) {
5116 stl_sc26198setreg(portp
, SCCR
, CR_CLEARRXERR
);
5117 ch
= stl_sc26198getreg(portp
, RXFIFO
);
5118 stl_sc26198rxbadch(portp
, status
, ch
);
5122 * To get correct interrupt class we must switch back into BLOCK
5125 stl_sc26198setreg(portp
, MR1
, mr1
);
5128 /*****************************************************************************/
5131 * Other interrupt handler. This includes modem signals, flow
5132 * control actions, etc. Most stuff is left to off-level interrupt
5136 static void stl_sc26198otherisr(stlport_t
*portp
, unsigned int iack
)
5138 unsigned char cir
, ipr
, xisr
;
5141 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
5144 cir
= stl_sc26198getglobreg(portp
, CIR
);
5146 switch (cir
& CIR_SUBTYPEMASK
) {
5148 ipr
= stl_sc26198getreg(portp
, IPR
);
5149 if (ipr
& IPR_DCDCHANGE
) {
5150 set_bit(ASYI_DCDCHANGE
, &portp
->istate
);
5151 schedule_work(&portp
->tqueue
);
5152 portp
->stats
.modem
++;
5155 case CIR_SUBXONXOFF
:
5156 xisr
= stl_sc26198getreg(portp
, XISR
);
5157 if (xisr
& XISR_RXXONGOT
) {
5158 set_bit(ASYI_TXFLOWED
, &portp
->istate
);
5159 portp
->stats
.txxoff
++;
5161 if (xisr
& XISR_RXXOFFGOT
) {
5162 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
5163 portp
->stats
.txxon
++;
5167 stl_sc26198setreg(portp
, SCCR
, CR_BREAKRESET
);
5168 stl_sc26198rxbadchars(portp
);
5175 /*****************************************************************************/