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/device.h>
44 #include <linux/delay.h>
47 #include <asm/uaccess.h>
50 #include <linux/pci.h>
53 /*****************************************************************************/
56 * Define different board types. Use the standard Stallion "assigned"
57 * board numbers. Boards supported in this driver are abbreviated as
58 * EIO = EasyIO and ECH = EasyConnection 8/32.
64 #define BRD_ECH64PCI 27
65 #define BRD_EASYIOPCI 28
68 * Define a configuration structure to hold the board configuration.
69 * Need to set this up in the code (for now) with the boards that are
70 * to be configured into the system. This is what needs to be modified
71 * when adding/removing/modifying boards. Each line entry in the
72 * stl_brdconf[] array is a board. Each line contains io/irq/memory
73 * ranges for that board (as well as what type of board it is).
75 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
76 * This line would configure an EasyIO board (4 or 8, no difference),
77 * at io address 2a0 and irq 10.
79 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
80 * This line will configure an EasyConnection 8/32 board at primary io
81 * address 2a8, secondary io address 280 and irq 12.
82 * Enter as many lines into this array as you want (only the first 4
83 * will actually be used!). Any combination of EasyIO and EasyConnection
84 * boards can be specified. EasyConnection 8/32 boards can share their
85 * secondary io addresses between each other.
87 * NOTE: there is no need to put any entries in this table for PCI
88 * boards. They will be found automatically by the driver - provided
89 * PCI BIOS32 support is compiled into the kernel.
96 unsigned long memaddr
;
101 static stlconf_t stl_brdconf
[] = {
102 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
105 static int stl_nrbrds
= ARRAY_SIZE(stl_brdconf
);
107 /*****************************************************************************/
110 * Define some important driver characteristics. Device major numbers
111 * allocated as per Linux Device Registry.
113 #ifndef STL_SIOMEMMAJOR
114 #define STL_SIOMEMMAJOR 28
116 #ifndef STL_SERIALMAJOR
117 #define STL_SERIALMAJOR 24
119 #ifndef STL_CALLOUTMAJOR
120 #define STL_CALLOUTMAJOR 25
124 * Set the TX buffer size. Bigger is better, but we don't want
125 * to chew too much memory with buffers!
127 #define STL_TXBUFLOW 512
128 #define STL_TXBUFSIZE 4096
130 /*****************************************************************************/
133 * Define our local driver identity first. Set up stuff to deal with
134 * all the local structures required by a serial tty driver.
136 static char *stl_drvtitle
= "Stallion Multiport Serial Driver";
137 static char *stl_drvname
= "stallion";
138 static char *stl_drvversion
= "5.6.0";
140 static struct tty_driver
*stl_serial
;
143 * Define a local default termios struct. All ports will be created
144 * with this termios initially. Basically all it defines is a raw port
145 * at 9600, 8 data bits, 1 stop bit.
147 static struct termios stl_deftermios
= {
148 .c_cflag
= (B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
),
153 * Define global stats structures. Not used often, and can be
154 * re-used for each stats call.
156 static comstats_t stl_comstats
;
157 static combrd_t stl_brdstats
;
158 static stlbrd_t stl_dummybrd
;
159 static stlport_t stl_dummyport
;
162 * Define global place to put buffer overflow characters.
164 static char stl_unwanted
[SC26198_RXFIFOSIZE
];
166 /*****************************************************************************/
168 static stlbrd_t
*stl_brds
[STL_MAXBRDS
];
171 * Per board state flags. Used with the state field of the board struct.
172 * Not really much here!
174 #define BRD_FOUND 0x1
177 * Define the port structure istate flags. These set of flags are
178 * modified at interrupt time - so setting and reseting them needs
179 * to be atomic. Use the bit clear/setting routines for this.
181 #define ASYI_TXBUSY 1
183 #define ASYI_DCDCHANGE 3
184 #define ASYI_TXFLOWED 4
187 * Define an array of board names as printable strings. Handy for
188 * referencing boards when printing trace and stuff.
190 static char *stl_brdnames
[] = {
222 /*****************************************************************************/
225 * Define some string labels for arguments passed from the module
226 * load line. These allow for easy board definitions, and easy
227 * modification of the io, memory and irq resoucres.
229 static int stl_nargs
= 0;
230 static char *board0
[4];
231 static char *board1
[4];
232 static char *board2
[4];
233 static char *board3
[4];
235 static char **stl_brdsp
[] = {
243 * Define a set of common board names, and types. This is used to
244 * parse any module arguments.
247 typedef struct stlbrdtype
{
252 static stlbrdtype_t stl_brdstr
[] = {
253 { "easyio", BRD_EASYIO
},
254 { "eio", BRD_EASYIO
},
255 { "20", BRD_EASYIO
},
256 { "ec8/32", BRD_ECH
},
257 { "ec8/32-at", BRD_ECH
},
258 { "ec8/32-isa", BRD_ECH
},
260 { "echat", BRD_ECH
},
262 { "ec8/32-mc", BRD_ECHMC
},
263 { "ec8/32-mca", BRD_ECHMC
},
264 { "echmc", BRD_ECHMC
},
265 { "echmca", BRD_ECHMC
},
267 { "ec8/32-pc", BRD_ECHPCI
},
268 { "ec8/32-pci", BRD_ECHPCI
},
269 { "26", BRD_ECHPCI
},
270 { "ec8/64-pc", BRD_ECH64PCI
},
271 { "ec8/64-pci", BRD_ECH64PCI
},
272 { "ech-pci", BRD_ECH64PCI
},
273 { "echpci", BRD_ECH64PCI
},
274 { "echpc", BRD_ECH64PCI
},
275 { "27", BRD_ECH64PCI
},
276 { "easyio-pc", BRD_EASYIOPCI
},
277 { "easyio-pci", BRD_EASYIOPCI
},
278 { "eio-pci", BRD_EASYIOPCI
},
279 { "eiopci", BRD_EASYIOPCI
},
280 { "28", BRD_EASYIOPCI
},
284 * Define the module agruments.
286 MODULE_AUTHOR("Greg Ungerer");
287 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
288 MODULE_LICENSE("GPL");
290 module_param_array(board0
, charp
, &stl_nargs
, 0);
291 MODULE_PARM_DESC(board0
, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
292 module_param_array(board1
, charp
, &stl_nargs
, 0);
293 MODULE_PARM_DESC(board1
, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
294 module_param_array(board2
, charp
, &stl_nargs
, 0);
295 MODULE_PARM_DESC(board2
, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
296 module_param_array(board3
, charp
, &stl_nargs
, 0);
297 MODULE_PARM_DESC(board3
, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
299 /*****************************************************************************/
302 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
303 * to the directly accessible io ports of these boards (not the uarts -
304 * they are in cd1400.h and sc26198.h).
306 #define EIO_8PORTRS 0x04
307 #define EIO_4PORTRS 0x05
308 #define EIO_8PORTDI 0x00
309 #define EIO_8PORTM 0x06
311 #define EIO_IDBITMASK 0x07
313 #define EIO_BRDMASK 0xf0
316 #define ID_BRD16 0x30
318 #define EIO_INTRPEND 0x08
319 #define EIO_INTEDGE 0x00
320 #define EIO_INTLEVEL 0x08
324 #define ECH_IDBITMASK 0xe0
325 #define ECH_BRDENABLE 0x08
326 #define ECH_BRDDISABLE 0x00
327 #define ECH_INTENABLE 0x01
328 #define ECH_INTDISABLE 0x00
329 #define ECH_INTLEVEL 0x02
330 #define ECH_INTEDGE 0x00
331 #define ECH_INTRPEND 0x01
332 #define ECH_BRDRESET 0x01
334 #define ECHMC_INTENABLE 0x01
335 #define ECHMC_BRDRESET 0x02
337 #define ECH_PNLSTATUS 2
338 #define ECH_PNL16PORT 0x20
339 #define ECH_PNLIDMASK 0x07
340 #define ECH_PNLXPID 0x40
341 #define ECH_PNLINTRPEND 0x80
343 #define ECH_ADDR2MASK 0x1e0
346 * Define the vector mapping bits for the programmable interrupt board
347 * hardware. These bits encode the interrupt for the board to use - it
348 * is software selectable (except the EIO-8M).
350 static unsigned char stl_vecmap
[] = {
351 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
352 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
356 * Lock ordering is that you may not take stallion_lock holding
360 static spinlock_t brd_lock
; /* Guard the board mapping */
361 static spinlock_t stallion_lock
; /* Guard the tty driver */
364 * Set up enable and disable macros for the ECH boards. They require
365 * the secondary io address space to be activated and deactivated.
366 * This way all ECH boards can share their secondary io region.
367 * If this is an ECH-PCI board then also need to set the page pointer
368 * to point to the correct page.
370 #define BRDENABLE(brdnr,pagenr) \
371 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
372 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
373 stl_brds[(brdnr)]->ioctrl); \
374 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
375 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
377 #define BRDDISABLE(brdnr) \
378 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
379 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
380 stl_brds[(brdnr)]->ioctrl);
382 #define STL_CD1400MAXBAUD 230400
383 #define STL_SC26198MAXBAUD 460800
385 #define STL_BAUDBASE 115200
386 #define STL_CLOSEDELAY (5 * HZ / 10)
388 /*****************************************************************************/
393 * Define the Stallion PCI vendor and device IDs.
395 #ifndef PCI_VENDOR_ID_STALLION
396 #define PCI_VENDOR_ID_STALLION 0x124d
398 #ifndef PCI_DEVICE_ID_ECHPCI832
399 #define PCI_DEVICE_ID_ECHPCI832 0x0000
401 #ifndef PCI_DEVICE_ID_ECHPCI864
402 #define PCI_DEVICE_ID_ECHPCI864 0x0002
404 #ifndef PCI_DEVICE_ID_EIOPCI
405 #define PCI_DEVICE_ID_EIOPCI 0x0003
409 * Define structure to hold all Stallion PCI boards.
411 typedef struct stlpcibrd
{
412 unsigned short vendid
;
413 unsigned short devid
;
417 static stlpcibrd_t stl_pcibrds
[] = {
418 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI864
, BRD_ECH64PCI
},
419 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_EIOPCI
, BRD_EASYIOPCI
},
420 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI832
, BRD_ECHPCI
},
421 { PCI_VENDOR_ID_NS
, PCI_DEVICE_ID_NS_87410
, BRD_ECHPCI
},
424 static int stl_nrpcibrds
= ARRAY_SIZE(stl_pcibrds
);
428 /*****************************************************************************/
431 * Define macros to extract a brd/port number from a minor number.
433 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
434 #define MINOR2PORT(min) ((min) & 0x3f)
437 * Define a baud rate table that converts termios baud rate selector
438 * into the actual baud rate value. All baud rate calculations are
439 * based on the actual baud rate required.
441 static unsigned int stl_baudrates
[] = {
442 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
443 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
447 * Define some handy local macros...
450 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
453 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
455 /*****************************************************************************/
458 * Declare all those functions in this driver!
461 static void stl_argbrds(void);
462 static int stl_parsebrd(stlconf_t
*confp
, char **argp
);
464 static unsigned long stl_atol(char *str
);
466 static int stl_init(void);
467 static int stl_open(struct tty_struct
*tty
, struct file
*filp
);
468 static void stl_close(struct tty_struct
*tty
, struct file
*filp
);
469 static int stl_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
);
470 static void stl_putchar(struct tty_struct
*tty
, unsigned char ch
);
471 static void stl_flushchars(struct tty_struct
*tty
);
472 static int stl_writeroom(struct tty_struct
*tty
);
473 static int stl_charsinbuffer(struct tty_struct
*tty
);
474 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
);
475 static void stl_settermios(struct tty_struct
*tty
, struct termios
*old
);
476 static void stl_throttle(struct tty_struct
*tty
);
477 static void stl_unthrottle(struct tty_struct
*tty
);
478 static void stl_stop(struct tty_struct
*tty
);
479 static void stl_start(struct tty_struct
*tty
);
480 static void stl_flushbuffer(struct tty_struct
*tty
);
481 static void stl_breakctl(struct tty_struct
*tty
, int state
);
482 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
);
483 static void stl_sendxchar(struct tty_struct
*tty
, char ch
);
484 static void stl_hangup(struct tty_struct
*tty
);
485 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
);
486 static int stl_portinfo(stlport_t
*portp
, int portnr
, char *pos
);
487 static int stl_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
);
489 static int stl_brdinit(stlbrd_t
*brdp
);
490 static int stl_initports(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
491 static int stl_getserial(stlport_t
*portp
, struct serial_struct __user
*sp
);
492 static int stl_setserial(stlport_t
*portp
, struct serial_struct __user
*sp
);
493 static int stl_getbrdstats(combrd_t __user
*bp
);
494 static int stl_getportstats(stlport_t
*portp
, comstats_t __user
*cp
);
495 static int stl_clrportstats(stlport_t
*portp
, comstats_t __user
*cp
);
496 static int stl_getportstruct(stlport_t __user
*arg
);
497 static int stl_getbrdstruct(stlbrd_t __user
*arg
);
498 static int stl_waitcarrier(stlport_t
*portp
, struct file
*filp
);
499 static int stl_eiointr(stlbrd_t
*brdp
);
500 static int stl_echatintr(stlbrd_t
*brdp
);
501 static int stl_echmcaintr(stlbrd_t
*brdp
);
502 static int stl_echpciintr(stlbrd_t
*brdp
);
503 static int stl_echpci64intr(stlbrd_t
*brdp
);
504 static void stl_offintr(void *private);
505 static stlbrd_t
*stl_allocbrd(void);
506 static stlport_t
*stl_getport(int brdnr
, int panelnr
, int portnr
);
508 static inline int stl_initbrds(void);
509 static inline int stl_initeio(stlbrd_t
*brdp
);
510 static inline int stl_initech(stlbrd_t
*brdp
);
511 static inline int stl_getbrdnr(void);
514 static inline int stl_findpcibrds(void);
515 static inline int stl_initpcibrd(int brdtype
, struct pci_dev
*devp
);
519 * CD1400 uart specific handling functions.
521 static void stl_cd1400setreg(stlport_t
*portp
, int regnr
, int value
);
522 static int stl_cd1400getreg(stlport_t
*portp
, int regnr
);
523 static int stl_cd1400updatereg(stlport_t
*portp
, int regnr
, int value
);
524 static int stl_cd1400panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
525 static void stl_cd1400portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
526 static void stl_cd1400setport(stlport_t
*portp
, struct termios
*tiosp
);
527 static int stl_cd1400getsignals(stlport_t
*portp
);
528 static void stl_cd1400setsignals(stlport_t
*portp
, int dtr
, int rts
);
529 static void stl_cd1400ccrwait(stlport_t
*portp
);
530 static void stl_cd1400enablerxtx(stlport_t
*portp
, int rx
, int tx
);
531 static void stl_cd1400startrxtx(stlport_t
*portp
, int rx
, int tx
);
532 static void stl_cd1400disableintrs(stlport_t
*portp
);
533 static void stl_cd1400sendbreak(stlport_t
*portp
, int len
);
534 static void stl_cd1400flowctrl(stlport_t
*portp
, int state
);
535 static void stl_cd1400sendflow(stlport_t
*portp
, int state
);
536 static void stl_cd1400flush(stlport_t
*portp
);
537 static int stl_cd1400datastate(stlport_t
*portp
);
538 static void stl_cd1400eiointr(stlpanel_t
*panelp
, unsigned int iobase
);
539 static void stl_cd1400echintr(stlpanel_t
*panelp
, unsigned int iobase
);
540 static void stl_cd1400txisr(stlpanel_t
*panelp
, int ioaddr
);
541 static void stl_cd1400rxisr(stlpanel_t
*panelp
, int ioaddr
);
542 static void stl_cd1400mdmisr(stlpanel_t
*panelp
, int ioaddr
);
544 static inline int stl_cd1400breakisr(stlport_t
*portp
, int ioaddr
);
547 * SC26198 uart specific handling functions.
549 static void stl_sc26198setreg(stlport_t
*portp
, int regnr
, int value
);
550 static int stl_sc26198getreg(stlport_t
*portp
, int regnr
);
551 static int stl_sc26198updatereg(stlport_t
*portp
, int regnr
, int value
);
552 static int stl_sc26198getglobreg(stlport_t
*portp
, int regnr
);
553 static int stl_sc26198panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
554 static void stl_sc26198portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
555 static void stl_sc26198setport(stlport_t
*portp
, struct termios
*tiosp
);
556 static int stl_sc26198getsignals(stlport_t
*portp
);
557 static void stl_sc26198setsignals(stlport_t
*portp
, int dtr
, int rts
);
558 static void stl_sc26198enablerxtx(stlport_t
*portp
, int rx
, int tx
);
559 static void stl_sc26198startrxtx(stlport_t
*portp
, int rx
, int tx
);
560 static void stl_sc26198disableintrs(stlport_t
*portp
);
561 static void stl_sc26198sendbreak(stlport_t
*portp
, int len
);
562 static void stl_sc26198flowctrl(stlport_t
*portp
, int state
);
563 static void stl_sc26198sendflow(stlport_t
*portp
, int state
);
564 static void stl_sc26198flush(stlport_t
*portp
);
565 static int stl_sc26198datastate(stlport_t
*portp
);
566 static void stl_sc26198wait(stlport_t
*portp
);
567 static void stl_sc26198txunflow(stlport_t
*portp
, struct tty_struct
*tty
);
568 static void stl_sc26198intr(stlpanel_t
*panelp
, unsigned int iobase
);
569 static void stl_sc26198txisr(stlport_t
*port
);
570 static void stl_sc26198rxisr(stlport_t
*port
, unsigned int iack
);
571 static void stl_sc26198rxbadch(stlport_t
*portp
, unsigned char status
, char ch
);
572 static void stl_sc26198rxbadchars(stlport_t
*portp
);
573 static void stl_sc26198otherisr(stlport_t
*port
, unsigned int iack
);
575 /*****************************************************************************/
578 * Generic UART support structure.
580 typedef struct uart
{
581 int (*panelinit
)(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
582 void (*portinit
)(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
583 void (*setport
)(stlport_t
*portp
, struct termios
*tiosp
);
584 int (*getsignals
)(stlport_t
*portp
);
585 void (*setsignals
)(stlport_t
*portp
, int dtr
, int rts
);
586 void (*enablerxtx
)(stlport_t
*portp
, int rx
, int tx
);
587 void (*startrxtx
)(stlport_t
*portp
, int rx
, int tx
);
588 void (*disableintrs
)(stlport_t
*portp
);
589 void (*sendbreak
)(stlport_t
*portp
, int len
);
590 void (*flowctrl
)(stlport_t
*portp
, int state
);
591 void (*sendflow
)(stlport_t
*portp
, int state
);
592 void (*flush
)(stlport_t
*portp
);
593 int (*datastate
)(stlport_t
*portp
);
594 void (*intr
)(stlpanel_t
*panelp
, unsigned int iobase
);
598 * Define some macros to make calling these functions nice and clean.
600 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
601 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
602 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
603 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
604 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
605 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
606 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
607 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
608 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
609 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
610 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
611 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
612 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
614 /*****************************************************************************/
617 * CD1400 UART specific data initialization.
619 static uart_t stl_cd1400uart
= {
623 stl_cd1400getsignals
,
624 stl_cd1400setsignals
,
625 stl_cd1400enablerxtx
,
627 stl_cd1400disableintrs
,
637 * Define the offsets within the register bank of a cd1400 based panel.
638 * These io address offsets are common to the EasyIO board as well.
646 #define EREG_BANKSIZE 8
648 #define CD1400_CLK 25000000
649 #define CD1400_CLK8M 20000000
652 * Define the cd1400 baud rate clocks. These are used when calculating
653 * what clock and divisor to use for the required baud rate. Also
654 * define the maximum baud rate allowed, and the default base baud.
656 static int stl_cd1400clkdivs
[] = {
657 CD1400_CLK0
, CD1400_CLK1
, CD1400_CLK2
, CD1400_CLK3
, CD1400_CLK4
660 /*****************************************************************************/
663 * SC26198 UART specific data initization.
665 static uart_t stl_sc26198uart
= {
666 stl_sc26198panelinit
,
669 stl_sc26198getsignals
,
670 stl_sc26198setsignals
,
671 stl_sc26198enablerxtx
,
672 stl_sc26198startrxtx
,
673 stl_sc26198disableintrs
,
674 stl_sc26198sendbreak
,
678 stl_sc26198datastate
,
683 * Define the offsets within the register bank of a sc26198 based panel.
691 #define XP_BANKSIZE 4
694 * Define the sc26198 baud rate table. Offsets within the table
695 * represent the actual baud rate selector of sc26198 registers.
697 static unsigned int sc26198_baudtable
[] = {
698 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
699 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
700 230400, 460800, 921600
703 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
705 /*****************************************************************************/
708 * Define the driver info for a user level control device. Used mainly
709 * to get at port stats - only not using the port device itself.
711 static struct file_operations stl_fsiomem
= {
712 .owner
= THIS_MODULE
,
713 .ioctl
= stl_memioctl
,
716 /*****************************************************************************/
718 static struct class *stallion_class
;
721 * Loadable module initialization stuff.
724 static int __init
stallion_module_init(void)
730 /*****************************************************************************/
732 static void __exit
stallion_module_exit(void)
740 printk("cleanup_module()\n");
743 printk(KERN_INFO
"Unloading %s: version %s\n", stl_drvtitle
,
747 * Free up all allocated resources used by the ports. This includes
748 * memory and interrupts. As part of this process we will also do
749 * a hangup on every open port - to try to flush out any processes
750 * hanging onto ports.
752 i
= tty_unregister_driver(stl_serial
);
753 put_tty_driver(stl_serial
);
755 printk("STALLION: failed to un-register tty driver, "
759 for (i
= 0; i
< 4; i
++)
760 class_device_destroy(stallion_class
, MKDEV(STL_SIOMEMMAJOR
, i
));
761 if ((i
= unregister_chrdev(STL_SIOMEMMAJOR
, "staliomem")))
762 printk("STALLION: failed to un-register serial memory device, "
764 class_destroy(stallion_class
);
766 for (i
= 0; (i
< stl_nrbrds
); i
++) {
767 if ((brdp
= stl_brds
[i
]) == (stlbrd_t
*) NULL
)
770 free_irq(brdp
->irq
, brdp
);
772 for (j
= 0; (j
< STL_MAXPANELS
); j
++) {
773 panelp
= brdp
->panels
[j
];
774 if (panelp
== (stlpanel_t
*) NULL
)
776 for (k
= 0; (k
< STL_PORTSPERPANEL
); k
++) {
777 portp
= panelp
->ports
[k
];
778 if (portp
== (stlport_t
*) NULL
)
780 if (portp
->tty
!= (struct tty_struct
*) NULL
)
781 stl_hangup(portp
->tty
);
782 kfree(portp
->tx
.buf
);
788 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
789 if (brdp
->iosize2
> 0)
790 release_region(brdp
->ioaddr2
, brdp
->iosize2
);
793 stl_brds
[i
] = (stlbrd_t
*) NULL
;
797 module_init(stallion_module_init
);
798 module_exit(stallion_module_exit
);
800 /*****************************************************************************/
803 * Check for any arguments passed in on the module load command line.
806 static void stl_argbrds(void)
813 printk("stl_argbrds()\n");
816 for (i
= stl_nrbrds
; (i
< stl_nargs
); i
++) {
817 memset(&conf
, 0, sizeof(conf
));
818 if (stl_parsebrd(&conf
, stl_brdsp
[i
]) == 0)
820 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
824 brdp
->brdtype
= conf
.brdtype
;
825 brdp
->ioaddr1
= conf
.ioaddr1
;
826 brdp
->ioaddr2
= conf
.ioaddr2
;
827 brdp
->irq
= conf
.irq
;
828 brdp
->irqtype
= conf
.irqtype
;
833 /*****************************************************************************/
836 * Convert an ascii string number into an unsigned long.
839 static unsigned long stl_atol(char *str
)
847 if ((*sp
== '0') && (*(sp
+1) == 'x')) {
850 } else if (*sp
== '0') {
857 for (; (*sp
!= 0); sp
++) {
858 c
= (*sp
> '9') ? (TOLOWER(*sp
) - 'a' + 10) : (*sp
- '0');
859 if ((c
< 0) || (c
>= base
)) {
860 printk("STALLION: invalid argument %s\n", str
);
864 val
= (val
* base
) + c
;
869 /*****************************************************************************/
872 * Parse the supplied argument string, into the board conf struct.
875 static int stl_parsebrd(stlconf_t
*confp
, char **argp
)
881 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp
, (int) argp
);
884 if ((argp
[0] == (char *) NULL
) || (*argp
[0] == 0))
887 for (sp
= argp
[0], i
= 0; ((*sp
!= 0) && (i
< 25)); sp
++, i
++)
890 for (i
= 0; i
< ARRAY_SIZE(stl_brdstr
); i
++) {
891 if (strcmp(stl_brdstr
[i
].name
, argp
[0]) == 0)
894 if (i
== ARRAY_SIZE(stl_brdstr
)) {
895 printk("STALLION: unknown board name, %s?\n", argp
[0]);
899 confp
->brdtype
= stl_brdstr
[i
].type
;
902 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
903 confp
->ioaddr1
= stl_atol(argp
[i
]);
905 if (confp
->brdtype
== BRD_ECH
) {
906 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
907 confp
->ioaddr2
= stl_atol(argp
[i
]);
910 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
911 confp
->irq
= stl_atol(argp
[i
]);
915 /*****************************************************************************/
918 * Allocate a new board structure. Fill out the basic info in it.
921 static stlbrd_t
*stl_allocbrd(void)
925 brdp
= kzalloc(sizeof(stlbrd_t
), GFP_KERNEL
);
927 printk("STALLION: failed to allocate memory (size=%Zd)\n",
932 brdp
->magic
= STL_BOARDMAGIC
;
936 /*****************************************************************************/
938 static int stl_open(struct tty_struct
*tty
, struct file
*filp
)
942 unsigned int minordev
;
943 int brdnr
, panelnr
, portnr
, rc
;
946 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty
,
947 (int) filp
, tty
->name
);
950 minordev
= tty
->index
;
951 brdnr
= MINOR2BRD(minordev
);
952 if (brdnr
>= stl_nrbrds
)
954 brdp
= stl_brds
[brdnr
];
955 if (brdp
== (stlbrd_t
*) NULL
)
957 minordev
= MINOR2PORT(minordev
);
958 for (portnr
= -1, panelnr
= 0; (panelnr
< STL_MAXPANELS
); panelnr
++) {
959 if (brdp
->panels
[panelnr
] == (stlpanel_t
*) NULL
)
961 if (minordev
< brdp
->panels
[panelnr
]->nrports
) {
965 minordev
-= brdp
->panels
[panelnr
]->nrports
;
970 portp
= brdp
->panels
[panelnr
]->ports
[portnr
];
971 if (portp
== (stlport_t
*) NULL
)
975 * On the first open of the device setup the port hardware, and
976 * initialize the per port data structure.
979 tty
->driver_data
= portp
;
982 if ((portp
->flags
& ASYNC_INITIALIZED
) == 0) {
983 if (!portp
->tx
.buf
) {
984 portp
->tx
.buf
= kmalloc(STL_TXBUFSIZE
, GFP_KERNEL
);
987 portp
->tx
.head
= portp
->tx
.buf
;
988 portp
->tx
.tail
= portp
->tx
.buf
;
990 stl_setport(portp
, tty
->termios
);
991 portp
->sigs
= stl_getsignals(portp
);
992 stl_setsignals(portp
, 1, 1);
993 stl_enablerxtx(portp
, 1, 1);
994 stl_startrxtx(portp
, 1, 0);
995 clear_bit(TTY_IO_ERROR
, &tty
->flags
);
996 portp
->flags
|= ASYNC_INITIALIZED
;
1000 * Check if this port is in the middle of closing. If so then wait
1001 * until it is closed then return error status, based on flag settings.
1002 * The sleep here does not need interrupt protection since the wakeup
1003 * for it is done with the same context.
1005 if (portp
->flags
& ASYNC_CLOSING
) {
1006 interruptible_sleep_on(&portp
->close_wait
);
1007 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1009 return -ERESTARTSYS
;
1013 * Based on type of open being done check if it can overlap with any
1014 * previous opens still in effect. If we are a normal serial device
1015 * then also we might have to wait for carrier.
1017 if (!(filp
->f_flags
& O_NONBLOCK
)) {
1018 if ((rc
= stl_waitcarrier(portp
, filp
)) != 0)
1021 portp
->flags
|= ASYNC_NORMAL_ACTIVE
;
1026 /*****************************************************************************/
1029 * Possibly need to wait for carrier (DCD signal) to come high. Say
1030 * maybe because if we are clocal then we don't need to wait...
1033 static int stl_waitcarrier(stlport_t
*portp
, struct file
*filp
)
1035 unsigned long flags
;
1039 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp
, (int) filp
);
1045 spin_lock_irqsave(&stallion_lock
, flags
);
1047 if (portp
->tty
->termios
->c_cflag
& CLOCAL
)
1050 portp
->openwaitcnt
++;
1051 if (! tty_hung_up_p(filp
))
1055 /* Takes brd_lock internally */
1056 stl_setsignals(portp
, 1, 1);
1057 if (tty_hung_up_p(filp
) ||
1058 ((portp
->flags
& ASYNC_INITIALIZED
) == 0)) {
1059 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1065 if (((portp
->flags
& ASYNC_CLOSING
) == 0) &&
1066 (doclocal
|| (portp
->sigs
& TIOCM_CD
))) {
1069 if (signal_pending(current
)) {
1074 interruptible_sleep_on(&portp
->open_wait
);
1077 if (! tty_hung_up_p(filp
))
1079 portp
->openwaitcnt
--;
1080 spin_unlock_irqrestore(&stallion_lock
, flags
);
1085 /*****************************************************************************/
1087 static void stl_close(struct tty_struct
*tty
, struct file
*filp
)
1090 unsigned long flags
;
1093 printk("stl_close(tty=%x,filp=%x)\n", (int) tty
, (int) filp
);
1096 portp
= tty
->driver_data
;
1097 if (portp
== (stlport_t
*) NULL
)
1100 spin_lock_irqsave(&stallion_lock
, flags
);
1101 if (tty_hung_up_p(filp
)) {
1102 spin_unlock_irqrestore(&stallion_lock
, flags
);
1105 if ((tty
->count
== 1) && (portp
->refcount
!= 1))
1106 portp
->refcount
= 1;
1107 if (portp
->refcount
-- > 1) {
1108 spin_unlock_irqrestore(&stallion_lock
, flags
);
1112 portp
->refcount
= 0;
1113 portp
->flags
|= ASYNC_CLOSING
;
1116 * May want to wait for any data to drain before closing. The BUSY
1117 * flag keeps track of whether we are still sending or not - it is
1118 * very accurate for the cd1400, not quite so for the sc26198.
1119 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1123 spin_unlock_irqrestore(&stallion_lock
, flags
);
1125 if (portp
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1126 tty_wait_until_sent(tty
, portp
->closing_wait
);
1127 stl_waituntilsent(tty
, (HZ
/ 2));
1130 spin_lock_irqsave(&stallion_lock
, flags
);
1131 portp
->flags
&= ~ASYNC_INITIALIZED
;
1132 spin_unlock_irqrestore(&stallion_lock
, flags
);
1134 stl_disableintrs(portp
);
1135 if (tty
->termios
->c_cflag
& HUPCL
)
1136 stl_setsignals(portp
, 0, 0);
1137 stl_enablerxtx(portp
, 0, 0);
1138 stl_flushbuffer(tty
);
1140 if (portp
->tx
.buf
!= (char *) NULL
) {
1141 kfree(portp
->tx
.buf
);
1142 portp
->tx
.buf
= (char *) NULL
;
1143 portp
->tx
.head
= (char *) NULL
;
1144 portp
->tx
.tail
= (char *) NULL
;
1146 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1147 tty_ldisc_flush(tty
);
1150 portp
->tty
= (struct tty_struct
*) NULL
;
1152 if (portp
->openwaitcnt
) {
1153 if (portp
->close_delay
)
1154 msleep_interruptible(jiffies_to_msecs(portp
->close_delay
));
1155 wake_up_interruptible(&portp
->open_wait
);
1158 portp
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1159 wake_up_interruptible(&portp
->close_wait
);
1162 /*****************************************************************************/
1165 * Write routine. Take data and stuff it in to the TX ring queue.
1166 * If transmit interrupts are not running then start them.
1169 static int stl_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
1172 unsigned int len
, stlen
;
1173 unsigned char *chbuf
;
1177 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1178 (int) tty
, (int) buf
, count
);
1181 portp
= tty
->driver_data
;
1182 if (portp
== (stlport_t
*) NULL
)
1184 if (portp
->tx
.buf
== (char *) NULL
)
1188 * If copying direct from user space we must cater for page faults,
1189 * causing us to "sleep" here for a while. To handle this copy in all
1190 * the data we need now, into a local buffer. Then when we got it all
1191 * copy it into the TX buffer.
1193 chbuf
= (unsigned char *) buf
;
1195 head
= portp
->tx
.head
;
1196 tail
= portp
->tx
.tail
;
1198 len
= STL_TXBUFSIZE
- (head
- tail
) - 1;
1199 stlen
= STL_TXBUFSIZE
- (head
- portp
->tx
.buf
);
1201 len
= tail
- head
- 1;
1205 len
= MIN(len
, count
);
1208 stlen
= MIN(len
, stlen
);
1209 memcpy(head
, chbuf
, stlen
);
1214 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
)) {
1215 head
= portp
->tx
.buf
;
1216 stlen
= tail
- head
;
1219 portp
->tx
.head
= head
;
1221 clear_bit(ASYI_TXLOW
, &portp
->istate
);
1222 stl_startrxtx(portp
, -1, 1);
1227 /*****************************************************************************/
1229 static void stl_putchar(struct tty_struct
*tty
, unsigned char ch
)
1236 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty
, (int) ch
);
1239 if (tty
== (struct tty_struct
*) NULL
)
1241 portp
= tty
->driver_data
;
1242 if (portp
== (stlport_t
*) NULL
)
1244 if (portp
->tx
.buf
== (char *) NULL
)
1247 head
= portp
->tx
.head
;
1248 tail
= portp
->tx
.tail
;
1250 len
= (head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
)) : (tail
- head
);
1255 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
1256 head
= portp
->tx
.buf
;
1258 portp
->tx
.head
= head
;
1261 /*****************************************************************************/
1264 * If there are any characters in the buffer then make sure that TX
1265 * interrupts are on and get'em out. Normally used after the putchar
1266 * routine has been called.
1269 static void stl_flushchars(struct tty_struct
*tty
)
1274 printk("stl_flushchars(tty=%x)\n", (int) tty
);
1277 if (tty
== (struct tty_struct
*) NULL
)
1279 portp
= tty
->driver_data
;
1280 if (portp
== (stlport_t
*) NULL
)
1282 if (portp
->tx
.buf
== (char *) NULL
)
1285 stl_startrxtx(portp
, -1, 1);
1288 /*****************************************************************************/
1290 static int stl_writeroom(struct tty_struct
*tty
)
1296 printk("stl_writeroom(tty=%x)\n", (int) tty
);
1299 if (tty
== (struct tty_struct
*) NULL
)
1301 portp
= tty
->driver_data
;
1302 if (portp
== (stlport_t
*) NULL
)
1304 if (portp
->tx
.buf
== (char *) NULL
)
1307 head
= portp
->tx
.head
;
1308 tail
= portp
->tx
.tail
;
1309 return ((head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
) - 1) : (tail
- head
- 1));
1312 /*****************************************************************************/
1315 * Return number of chars in the TX buffer. Normally we would just
1316 * calculate the number of chars in the buffer and return that, but if
1317 * the buffer is empty and TX interrupts are still on then we return
1318 * that the buffer still has 1 char in it. This way whoever called us
1319 * will not think that ALL chars have drained - since the UART still
1320 * must have some chars in it (we are busy after all).
1323 static int stl_charsinbuffer(struct tty_struct
*tty
)
1330 printk("stl_charsinbuffer(tty=%x)\n", (int) tty
);
1333 if (tty
== (struct tty_struct
*) NULL
)
1335 portp
= tty
->driver_data
;
1336 if (portp
== (stlport_t
*) NULL
)
1338 if (portp
->tx
.buf
== (char *) NULL
)
1341 head
= portp
->tx
.head
;
1342 tail
= portp
->tx
.tail
;
1343 size
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
1344 if ((size
== 0) && test_bit(ASYI_TXBUSY
, &portp
->istate
))
1349 /*****************************************************************************/
1352 * Generate the serial struct info.
1355 static int stl_getserial(stlport_t
*portp
, struct serial_struct __user
*sp
)
1357 struct serial_struct sio
;
1361 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
1364 memset(&sio
, 0, sizeof(struct serial_struct
));
1365 sio
.line
= portp
->portnr
;
1366 sio
.port
= portp
->ioaddr
;
1367 sio
.flags
= portp
->flags
;
1368 sio
.baud_base
= portp
->baud_base
;
1369 sio
.close_delay
= portp
->close_delay
;
1370 sio
.closing_wait
= portp
->closing_wait
;
1371 sio
.custom_divisor
= portp
->custom_divisor
;
1373 if (portp
->uartp
== &stl_cd1400uart
) {
1374 sio
.type
= PORT_CIRRUS
;
1375 sio
.xmit_fifo_size
= CD1400_TXFIFOSIZE
;
1377 sio
.type
= PORT_UNKNOWN
;
1378 sio
.xmit_fifo_size
= SC26198_TXFIFOSIZE
;
1381 brdp
= stl_brds
[portp
->brdnr
];
1382 if (brdp
!= (stlbrd_t
*) NULL
)
1383 sio
.irq
= brdp
->irq
;
1385 return copy_to_user(sp
, &sio
, sizeof(struct serial_struct
)) ? -EFAULT
: 0;
1388 /*****************************************************************************/
1391 * Set port according to the serial struct info.
1392 * At this point we do not do any auto-configure stuff, so we will
1393 * just quietly ignore any requests to change irq, etc.
1396 static int stl_setserial(stlport_t
*portp
, struct serial_struct __user
*sp
)
1398 struct serial_struct sio
;
1401 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
1404 if (copy_from_user(&sio
, sp
, sizeof(struct serial_struct
)))
1406 if (!capable(CAP_SYS_ADMIN
)) {
1407 if ((sio
.baud_base
!= portp
->baud_base
) ||
1408 (sio
.close_delay
!= portp
->close_delay
) ||
1409 ((sio
.flags
& ~ASYNC_USR_MASK
) !=
1410 (portp
->flags
& ~ASYNC_USR_MASK
)))
1414 portp
->flags
= (portp
->flags
& ~ASYNC_USR_MASK
) |
1415 (sio
.flags
& ASYNC_USR_MASK
);
1416 portp
->baud_base
= sio
.baud_base
;
1417 portp
->close_delay
= sio
.close_delay
;
1418 portp
->closing_wait
= sio
.closing_wait
;
1419 portp
->custom_divisor
= sio
.custom_divisor
;
1420 stl_setport(portp
, portp
->tty
->termios
);
1424 /*****************************************************************************/
1426 static int stl_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1430 if (tty
== (struct tty_struct
*) NULL
)
1432 portp
= tty
->driver_data
;
1433 if (portp
== (stlport_t
*) NULL
)
1435 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1438 return stl_getsignals(portp
);
1441 static int stl_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1442 unsigned int set
, unsigned int clear
)
1445 int rts
= -1, dtr
= -1;
1447 if (tty
== (struct tty_struct
*) NULL
)
1449 portp
= tty
->driver_data
;
1450 if (portp
== (stlport_t
*) NULL
)
1452 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1455 if (set
& TIOCM_RTS
)
1457 if (set
& TIOCM_DTR
)
1459 if (clear
& TIOCM_RTS
)
1461 if (clear
& TIOCM_DTR
)
1464 stl_setsignals(portp
, dtr
, rts
);
1468 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1473 void __user
*argp
= (void __user
*)arg
;
1476 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1477 (int) tty
, (int) file
, cmd
, (int) arg
);
1480 if (tty
== (struct tty_struct
*) NULL
)
1482 portp
= tty
->driver_data
;
1483 if (portp
== (stlport_t
*) NULL
)
1486 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1487 (cmd
!= COM_GETPORTSTATS
) && (cmd
!= COM_CLRPORTSTATS
)) {
1488 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1496 rc
= put_user(((tty
->termios
->c_cflag
& CLOCAL
) ? 1 : 0),
1497 (unsigned __user
*) argp
);
1500 if (get_user(ival
, (unsigned int __user
*) arg
))
1502 tty
->termios
->c_cflag
=
1503 (tty
->termios
->c_cflag
& ~CLOCAL
) |
1504 (ival
? CLOCAL
: 0);
1507 rc
= stl_getserial(portp
, argp
);
1510 rc
= stl_setserial(portp
, argp
);
1512 case COM_GETPORTSTATS
:
1513 rc
= stl_getportstats(portp
, argp
);
1515 case COM_CLRPORTSTATS
:
1516 rc
= stl_clrportstats(portp
, argp
);
1522 case TIOCSERGSTRUCT
:
1523 case TIOCSERGETMULTI
:
1524 case TIOCSERSETMULTI
:
1533 /*****************************************************************************/
1535 static void stl_settermios(struct tty_struct
*tty
, struct termios
*old
)
1538 struct termios
*tiosp
;
1541 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty
, (int) old
);
1544 if (tty
== (struct tty_struct
*) NULL
)
1546 portp
= tty
->driver_data
;
1547 if (portp
== (stlport_t
*) NULL
)
1550 tiosp
= tty
->termios
;
1551 if ((tiosp
->c_cflag
== old
->c_cflag
) &&
1552 (tiosp
->c_iflag
== old
->c_iflag
))
1555 stl_setport(portp
, tiosp
);
1556 stl_setsignals(portp
, ((tiosp
->c_cflag
& (CBAUD
& ~CBAUDEX
)) ? 1 : 0),
1558 if ((old
->c_cflag
& CRTSCTS
) && ((tiosp
->c_cflag
& CRTSCTS
) == 0)) {
1559 tty
->hw_stopped
= 0;
1562 if (((old
->c_cflag
& CLOCAL
) == 0) && (tiosp
->c_cflag
& CLOCAL
))
1563 wake_up_interruptible(&portp
->open_wait
);
1566 /*****************************************************************************/
1569 * Attempt to flow control who ever is sending us data. Based on termios
1570 * settings use software or/and hardware flow control.
1573 static void stl_throttle(struct tty_struct
*tty
)
1578 printk("stl_throttle(tty=%x)\n", (int) tty
);
1581 if (tty
== (struct tty_struct
*) NULL
)
1583 portp
= tty
->driver_data
;
1584 if (portp
== (stlport_t
*) NULL
)
1586 stl_flowctrl(portp
, 0);
1589 /*****************************************************************************/
1592 * Unflow control the device sending us data...
1595 static void stl_unthrottle(struct tty_struct
*tty
)
1600 printk("stl_unthrottle(tty=%x)\n", (int) tty
);
1603 if (tty
== (struct tty_struct
*) NULL
)
1605 portp
= tty
->driver_data
;
1606 if (portp
== (stlport_t
*) NULL
)
1608 stl_flowctrl(portp
, 1);
1611 /*****************************************************************************/
1614 * Stop the transmitter. Basically to do this we will just turn TX
1618 static void stl_stop(struct tty_struct
*tty
)
1623 printk("stl_stop(tty=%x)\n", (int) tty
);
1626 if (tty
== (struct tty_struct
*) NULL
)
1628 portp
= tty
->driver_data
;
1629 if (portp
== (stlport_t
*) NULL
)
1631 stl_startrxtx(portp
, -1, 0);
1634 /*****************************************************************************/
1637 * Start the transmitter again. Just turn TX interrupts back on.
1640 static void stl_start(struct tty_struct
*tty
)
1645 printk("stl_start(tty=%x)\n", (int) tty
);
1648 if (tty
== (struct tty_struct
*) NULL
)
1650 portp
= tty
->driver_data
;
1651 if (portp
== (stlport_t
*) NULL
)
1653 stl_startrxtx(portp
, -1, 1);
1656 /*****************************************************************************/
1659 * Hangup this port. This is pretty much like closing the port, only
1660 * a little more brutal. No waiting for data to drain. Shutdown the
1661 * port and maybe drop signals.
1664 static void stl_hangup(struct tty_struct
*tty
)
1669 printk("stl_hangup(tty=%x)\n", (int) tty
);
1672 if (tty
== (struct tty_struct
*) NULL
)
1674 portp
= tty
->driver_data
;
1675 if (portp
== (stlport_t
*) NULL
)
1678 portp
->flags
&= ~ASYNC_INITIALIZED
;
1679 stl_disableintrs(portp
);
1680 if (tty
->termios
->c_cflag
& HUPCL
)
1681 stl_setsignals(portp
, 0, 0);
1682 stl_enablerxtx(portp
, 0, 0);
1683 stl_flushbuffer(tty
);
1685 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1686 if (portp
->tx
.buf
!= (char *) NULL
) {
1687 kfree(portp
->tx
.buf
);
1688 portp
->tx
.buf
= (char *) NULL
;
1689 portp
->tx
.head
= (char *) NULL
;
1690 portp
->tx
.tail
= (char *) NULL
;
1692 portp
->tty
= (struct tty_struct
*) NULL
;
1693 portp
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1694 portp
->refcount
= 0;
1695 wake_up_interruptible(&portp
->open_wait
);
1698 /*****************************************************************************/
1700 static void stl_flushbuffer(struct tty_struct
*tty
)
1705 printk("stl_flushbuffer(tty=%x)\n", (int) tty
);
1708 if (tty
== (struct tty_struct
*) NULL
)
1710 portp
= tty
->driver_data
;
1711 if (portp
== (stlport_t
*) NULL
)
1718 /*****************************************************************************/
1720 static void stl_breakctl(struct tty_struct
*tty
, int state
)
1725 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty
, state
);
1728 if (tty
== (struct tty_struct
*) NULL
)
1730 portp
= tty
->driver_data
;
1731 if (portp
== (stlport_t
*) NULL
)
1734 stl_sendbreak(portp
, ((state
== -1) ? 1 : 2));
1737 /*****************************************************************************/
1739 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
)
1745 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty
, timeout
);
1748 if (tty
== (struct tty_struct
*) NULL
)
1750 portp
= tty
->driver_data
;
1751 if (portp
== (stlport_t
*) NULL
)
1756 tend
= jiffies
+ timeout
;
1758 while (stl_datastate(portp
)) {
1759 if (signal_pending(current
))
1761 msleep_interruptible(20);
1762 if (time_after_eq(jiffies
, tend
))
1767 /*****************************************************************************/
1769 static void stl_sendxchar(struct tty_struct
*tty
, char ch
)
1774 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty
, ch
);
1777 if (tty
== (struct tty_struct
*) NULL
)
1779 portp
= tty
->driver_data
;
1780 if (portp
== (stlport_t
*) NULL
)
1783 if (ch
== STOP_CHAR(tty
))
1784 stl_sendflow(portp
, 0);
1785 else if (ch
== START_CHAR(tty
))
1786 stl_sendflow(portp
, 1);
1788 stl_putchar(tty
, ch
);
1791 /*****************************************************************************/
1796 * Format info for a specified port. The line is deliberately limited
1797 * to 80 characters. (If it is too long it will be truncated, if too
1798 * short then padded with spaces).
1801 static int stl_portinfo(stlport_t
*portp
, int portnr
, char *pos
)
1807 sp
+= sprintf(sp
, "%d: uart:%s tx:%d rx:%d",
1808 portnr
, (portp
->hwid
== 1) ? "SC26198" : "CD1400",
1809 (int) portp
->stats
.txtotal
, (int) portp
->stats
.rxtotal
);
1811 if (portp
->stats
.rxframing
)
1812 sp
+= sprintf(sp
, " fe:%d", (int) portp
->stats
.rxframing
);
1813 if (portp
->stats
.rxparity
)
1814 sp
+= sprintf(sp
, " pe:%d", (int) portp
->stats
.rxparity
);
1815 if (portp
->stats
.rxbreaks
)
1816 sp
+= sprintf(sp
, " brk:%d", (int) portp
->stats
.rxbreaks
);
1817 if (portp
->stats
.rxoverrun
)
1818 sp
+= sprintf(sp
, " oe:%d", (int) portp
->stats
.rxoverrun
);
1820 sigs
= stl_getsignals(portp
);
1821 cnt
= sprintf(sp
, "%s%s%s%s%s ",
1822 (sigs
& TIOCM_RTS
) ? "|RTS" : "",
1823 (sigs
& TIOCM_CTS
) ? "|CTS" : "",
1824 (sigs
& TIOCM_DTR
) ? "|DTR" : "",
1825 (sigs
& TIOCM_CD
) ? "|DCD" : "",
1826 (sigs
& TIOCM_DSR
) ? "|DSR" : "");
1830 for (cnt
= (sp
- pos
); (cnt
< (MAXLINE
- 1)); cnt
++)
1833 pos
[(MAXLINE
- 2)] = '+';
1834 pos
[(MAXLINE
- 1)] = '\n';
1839 /*****************************************************************************/
1842 * Port info, read from the /proc file system.
1845 static int stl_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
1850 int brdnr
, panelnr
, portnr
, totalport
;
1855 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1856 "data=%x\n", (int) page
, (int) start
, (int) off
, count
,
1857 (int) eof
, (int) data
);
1865 pos
+= sprintf(pos
, "%s: version %s", stl_drvtitle
,
1867 while (pos
< (page
+ MAXLINE
- 1))
1874 * We scan through for each board, panel and port. The offset is
1875 * calculated on the fly, and irrelevant ports are skipped.
1877 for (brdnr
= 0; (brdnr
< stl_nrbrds
); brdnr
++) {
1878 brdp
= stl_brds
[brdnr
];
1879 if (brdp
== (stlbrd_t
*) NULL
)
1881 if (brdp
->state
== 0)
1884 maxoff
= curoff
+ (brdp
->nrports
* MAXLINE
);
1885 if (off
>= maxoff
) {
1890 totalport
= brdnr
* STL_MAXPORTS
;
1891 for (panelnr
= 0; (panelnr
< brdp
->nrpanels
); panelnr
++) {
1892 panelp
= brdp
->panels
[panelnr
];
1893 if (panelp
== (stlpanel_t
*) NULL
)
1896 maxoff
= curoff
+ (panelp
->nrports
* MAXLINE
);
1897 if (off
>= maxoff
) {
1899 totalport
+= panelp
->nrports
;
1903 for (portnr
= 0; (portnr
< panelp
->nrports
); portnr
++,
1905 portp
= panelp
->ports
[portnr
];
1906 if (portp
== (stlport_t
*) NULL
)
1908 if (off
>= (curoff
+= MAXLINE
))
1910 if ((pos
- page
+ MAXLINE
) > count
)
1912 pos
+= stl_portinfo(portp
, totalport
, pos
);
1921 return (pos
- page
);
1924 /*****************************************************************************/
1927 * All board interrupts are vectored through here first. This code then
1928 * calls off to the approrpriate board interrupt handlers.
1931 static irqreturn_t
stl_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
1933 stlbrd_t
*brdp
= (stlbrd_t
*) dev_id
;
1936 printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp
, irq
,
1940 return IRQ_RETVAL((* brdp
->isr
)(brdp
));
1943 /*****************************************************************************/
1946 * Interrupt service routine for EasyIO board types.
1949 static int stl_eiointr(stlbrd_t
*brdp
)
1952 unsigned int iobase
;
1955 spin_lock(&brd_lock
);
1956 panelp
= brdp
->panels
[0];
1957 iobase
= panelp
->iobase
;
1958 while (inb(brdp
->iostatus
) & EIO_INTRPEND
) {
1960 (* panelp
->isr
)(panelp
, iobase
);
1962 spin_unlock(&brd_lock
);
1966 /*****************************************************************************/
1969 * Interrupt service routine for ECH-AT board types.
1972 static int stl_echatintr(stlbrd_t
*brdp
)
1975 unsigned int ioaddr
;
1979 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
1981 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
1983 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
1984 ioaddr
= brdp
->bnkstataddr
[bnknr
];
1985 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
1986 panelp
= brdp
->bnk2panel
[bnknr
];
1987 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
1992 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
1997 /*****************************************************************************/
2000 * Interrupt service routine for ECH-MCA board types.
2003 static int stl_echmcaintr(stlbrd_t
*brdp
)
2006 unsigned int ioaddr
;
2010 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
2012 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2013 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2014 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2015 panelp
= brdp
->bnk2panel
[bnknr
];
2016 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2023 /*****************************************************************************/
2026 * Interrupt service routine for ECH-PCI board types.
2029 static int stl_echpciintr(stlbrd_t
*brdp
)
2032 unsigned int ioaddr
;
2038 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2039 outb(brdp
->bnkpageaddr
[bnknr
], brdp
->ioctrl
);
2040 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2041 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2042 panelp
= brdp
->bnk2panel
[bnknr
];
2043 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2054 /*****************************************************************************/
2057 * Interrupt service routine for ECH-8/64-PCI board types.
2060 static int stl_echpci64intr(stlbrd_t
*brdp
)
2063 unsigned int ioaddr
;
2067 while (inb(brdp
->ioctrl
) & 0x1) {
2069 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2070 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2071 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2072 panelp
= brdp
->bnk2panel
[bnknr
];
2073 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2081 /*****************************************************************************/
2084 * Service an off-level request for some channel.
2086 static void stl_offintr(void *private)
2089 struct tty_struct
*tty
;
2090 unsigned int oldsigs
;
2095 printk("stl_offintr(portp=%x)\n", (int) portp
);
2098 if (portp
== (stlport_t
*) NULL
)
2102 if (tty
== (struct tty_struct
*) NULL
)
2106 if (test_bit(ASYI_TXLOW
, &portp
->istate
)) {
2109 if (test_bit(ASYI_DCDCHANGE
, &portp
->istate
)) {
2110 clear_bit(ASYI_DCDCHANGE
, &portp
->istate
);
2111 oldsigs
= portp
->sigs
;
2112 portp
->sigs
= stl_getsignals(portp
);
2113 if ((portp
->sigs
& TIOCM_CD
) && ((oldsigs
& TIOCM_CD
) == 0))
2114 wake_up_interruptible(&portp
->open_wait
);
2115 if ((oldsigs
& TIOCM_CD
) && ((portp
->sigs
& TIOCM_CD
) == 0)) {
2116 if (portp
->flags
& ASYNC_CHECK_CD
)
2117 tty_hangup(tty
); /* FIXME: module removal race here - AKPM */
2123 /*****************************************************************************/
2126 * Initialize all the ports on a panel.
2129 static int __init
stl_initports(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
2135 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
2138 chipmask
= stl_panelinit(brdp
, panelp
);
2141 * All UART's are initialized (if found!). Now go through and setup
2142 * each ports data structures.
2144 for (i
= 0; (i
< panelp
->nrports
); i
++) {
2145 portp
= kzalloc(sizeof(stlport_t
), GFP_KERNEL
);
2147 printk("STALLION: failed to allocate memory "
2148 "(size=%Zd)\n", sizeof(stlport_t
));
2152 portp
->magic
= STL_PORTMAGIC
;
2154 portp
->brdnr
= panelp
->brdnr
;
2155 portp
->panelnr
= panelp
->panelnr
;
2156 portp
->uartp
= panelp
->uartp
;
2157 portp
->clk
= brdp
->clk
;
2158 portp
->baud_base
= STL_BAUDBASE
;
2159 portp
->close_delay
= STL_CLOSEDELAY
;
2160 portp
->closing_wait
= 30 * HZ
;
2161 INIT_WORK(&portp
->tqueue
, stl_offintr
, portp
);
2162 init_waitqueue_head(&portp
->open_wait
);
2163 init_waitqueue_head(&portp
->close_wait
);
2164 portp
->stats
.brd
= portp
->brdnr
;
2165 portp
->stats
.panel
= portp
->panelnr
;
2166 portp
->stats
.port
= portp
->portnr
;
2167 panelp
->ports
[i
] = portp
;
2168 stl_portinit(brdp
, panelp
, portp
);
2174 /*****************************************************************************/
2177 * Try to find and initialize an EasyIO board.
2180 static inline int stl_initeio(stlbrd_t
*brdp
)
2183 unsigned int status
;
2188 printk("stl_initeio(brdp=%x)\n", (int) brdp
);
2191 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2192 brdp
->iostatus
= brdp
->ioaddr1
+ 2;
2194 status
= inb(brdp
->iostatus
);
2195 if ((status
& EIO_IDBITMASK
) == EIO_MK3
)
2199 * Handle board specific stuff now. The real difference is PCI
2202 if (brdp
->brdtype
== BRD_EASYIOPCI
) {
2203 brdp
->iosize1
= 0x80;
2204 brdp
->iosize2
= 0x80;
2205 name
= "serial(EIO-PCI)";
2206 outb(0x41, (brdp
->ioaddr2
+ 0x4c));
2209 name
= "serial(EIO)";
2210 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2211 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2212 printk("STALLION: invalid irq=%d for brd=%d\n",
2213 brdp
->irq
, brdp
->brdnr
);
2216 outb((stl_vecmap
[brdp
->irq
] | EIO_0WS
|
2217 ((brdp
->irqtype
) ? EIO_INTLEVEL
: EIO_INTEDGE
)),
2221 if (!request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
)) {
2222 printk(KERN_WARNING
"STALLION: Warning, board %d I/O address "
2223 "%x conflicts with another device\n", brdp
->brdnr
,
2228 if (brdp
->iosize2
> 0)
2229 if (!request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
)) {
2230 printk(KERN_WARNING
"STALLION: Warning, board %d I/O "
2231 "address %x conflicts with another device\n",
2232 brdp
->brdnr
, brdp
->ioaddr2
);
2233 printk(KERN_WARNING
"STALLION: Warning, also "
2234 "releasing board %d I/O address %x \n",
2235 brdp
->brdnr
, brdp
->ioaddr1
);
2236 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
2241 * Everything looks OK, so let's go ahead and probe for the hardware.
2243 brdp
->clk
= CD1400_CLK
;
2244 brdp
->isr
= stl_eiointr
;
2246 switch (status
& EIO_IDBITMASK
) {
2248 brdp
->clk
= CD1400_CLK8M
;
2258 switch (status
& EIO_BRDMASK
) {
2277 * We have verified that the board is actually present, so now we
2278 * can complete the setup.
2281 panelp
= kzalloc(sizeof(stlpanel_t
), GFP_KERNEL
);
2283 printk(KERN_WARNING
"STALLION: failed to allocate memory "
2284 "(size=%Zd)\n", sizeof(stlpanel_t
));
2288 panelp
->magic
= STL_PANELMAGIC
;
2289 panelp
->brdnr
= brdp
->brdnr
;
2290 panelp
->panelnr
= 0;
2291 panelp
->nrports
= brdp
->nrports
;
2292 panelp
->iobase
= brdp
->ioaddr1
;
2293 panelp
->hwid
= status
;
2294 if ((status
& EIO_IDBITMASK
) == EIO_MK3
) {
2295 panelp
->uartp
= (void *) &stl_sc26198uart
;
2296 panelp
->isr
= stl_sc26198intr
;
2298 panelp
->uartp
= (void *) &stl_cd1400uart
;
2299 panelp
->isr
= stl_cd1400eiointr
;
2302 brdp
->panels
[0] = panelp
;
2304 brdp
->state
|= BRD_FOUND
;
2305 brdp
->hwid
= status
;
2306 if (request_irq(brdp
->irq
, stl_intr
, SA_SHIRQ
, name
, brdp
) != 0) {
2307 printk("STALLION: failed to register interrupt "
2308 "routine for %s irq=%d\n", name
, brdp
->irq
);
2316 /*****************************************************************************/
2319 * Try to find an ECH board and initialize it. This code is capable of
2320 * dealing with all types of ECH board.
2323 static inline int stl_initech(stlbrd_t
*brdp
)
2326 unsigned int status
, nxtid
, ioaddr
, conflict
;
2327 int panelnr
, banknr
, i
;
2331 printk("stl_initech(brdp=%x)\n", (int) brdp
);
2338 * Set up the initial board register contents for boards. This varies a
2339 * bit between the different board types. So we need to handle each
2340 * separately. Also do a check that the supplied IRQ is good.
2342 switch (brdp
->brdtype
) {
2345 brdp
->isr
= stl_echatintr
;
2346 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2347 brdp
->iostatus
= brdp
->ioaddr1
+ 1;
2348 status
= inb(brdp
->iostatus
);
2349 if ((status
& ECH_IDBITMASK
) != ECH_ID
)
2351 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2352 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2353 printk("STALLION: invalid irq=%d for brd=%d\n",
2354 brdp
->irq
, brdp
->brdnr
);
2357 status
= ((brdp
->ioaddr2
& ECH_ADDR2MASK
) >> 1);
2358 status
|= (stl_vecmap
[brdp
->irq
] << 1);
2359 outb((status
| ECH_BRDRESET
), brdp
->ioaddr1
);
2360 brdp
->ioctrlval
= ECH_INTENABLE
|
2361 ((brdp
->irqtype
) ? ECH_INTLEVEL
: ECH_INTEDGE
);
2362 for (i
= 0; (i
< 10); i
++)
2363 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
2366 name
= "serial(EC8/32)";
2367 outb(status
, brdp
->ioaddr1
);
2371 brdp
->isr
= stl_echmcaintr
;
2372 brdp
->ioctrl
= brdp
->ioaddr1
+ 0x20;
2373 brdp
->iostatus
= brdp
->ioctrl
;
2374 status
= inb(brdp
->iostatus
);
2375 if ((status
& ECH_IDBITMASK
) != ECH_ID
)
2377 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2378 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2379 printk("STALLION: invalid irq=%d for brd=%d\n",
2380 brdp
->irq
, brdp
->brdnr
);
2383 outb(ECHMC_BRDRESET
, brdp
->ioctrl
);
2384 outb(ECHMC_INTENABLE
, brdp
->ioctrl
);
2386 name
= "serial(EC8/32-MC)";
2390 brdp
->isr
= stl_echpciintr
;
2391 brdp
->ioctrl
= brdp
->ioaddr1
+ 2;
2394 name
= "serial(EC8/32-PCI)";
2398 brdp
->isr
= stl_echpci64intr
;
2399 brdp
->ioctrl
= brdp
->ioaddr2
+ 0x40;
2400 outb(0x43, (brdp
->ioaddr1
+ 0x4c));
2401 brdp
->iosize1
= 0x80;
2402 brdp
->iosize2
= 0x80;
2403 name
= "serial(EC8/64-PCI)";
2407 printk("STALLION: unknown board type=%d\n", brdp
->brdtype
);
2413 * Check boards for possible IO address conflicts and return fail status
2414 * if an IO conflict found.
2416 if (!request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
)) {
2417 printk(KERN_WARNING
"STALLION: Warning, board %d I/O address "
2418 "%x conflicts with another device\n", brdp
->brdnr
,
2423 if (brdp
->iosize2
> 0)
2424 if (!request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
)) {
2425 printk(KERN_WARNING
"STALLION: Warning, board %d I/O "
2426 "address %x conflicts with another device\n",
2427 brdp
->brdnr
, brdp
->ioaddr2
);
2428 printk(KERN_WARNING
"STALLION: Warning, also "
2429 "releasing board %d I/O address %x \n",
2430 brdp
->brdnr
, brdp
->ioaddr1
);
2431 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
2436 * Scan through the secondary io address space looking for panels.
2437 * As we find'em allocate and initialize panel structures for each.
2439 brdp
->clk
= CD1400_CLK
;
2440 brdp
->hwid
= status
;
2442 ioaddr
= brdp
->ioaddr2
;
2447 for (i
= 0; (i
< STL_MAXPANELS
); i
++) {
2448 if (brdp
->brdtype
== BRD_ECHPCI
) {
2449 outb(nxtid
, brdp
->ioctrl
);
2450 ioaddr
= brdp
->ioaddr2
;
2452 status
= inb(ioaddr
+ ECH_PNLSTATUS
);
2453 if ((status
& ECH_PNLIDMASK
) != nxtid
)
2455 panelp
= kzalloc(sizeof(stlpanel_t
), GFP_KERNEL
);
2457 printk("STALLION: failed to allocate memory "
2458 "(size=%Zd)\n", sizeof(stlpanel_t
));
2461 panelp
->magic
= STL_PANELMAGIC
;
2462 panelp
->brdnr
= brdp
->brdnr
;
2463 panelp
->panelnr
= panelnr
;
2464 panelp
->iobase
= ioaddr
;
2465 panelp
->pagenr
= nxtid
;
2466 panelp
->hwid
= status
;
2467 brdp
->bnk2panel
[banknr
] = panelp
;
2468 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2469 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ ECH_PNLSTATUS
;
2471 if (status
& ECH_PNLXPID
) {
2472 panelp
->uartp
= (void *) &stl_sc26198uart
;
2473 panelp
->isr
= stl_sc26198intr
;
2474 if (status
& ECH_PNL16PORT
) {
2475 panelp
->nrports
= 16;
2476 brdp
->bnk2panel
[banknr
] = panelp
;
2477 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2478 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ 4 +
2481 panelp
->nrports
= 8;
2484 panelp
->uartp
= (void *) &stl_cd1400uart
;
2485 panelp
->isr
= stl_cd1400echintr
;
2486 if (status
& ECH_PNL16PORT
) {
2487 panelp
->nrports
= 16;
2488 panelp
->ackmask
= 0x80;
2489 if (brdp
->brdtype
!= BRD_ECHPCI
)
2490 ioaddr
+= EREG_BANKSIZE
;
2491 brdp
->bnk2panel
[banknr
] = panelp
;
2492 brdp
->bnkpageaddr
[banknr
] = ++nxtid
;
2493 brdp
->bnkstataddr
[banknr
++] = ioaddr
+
2496 panelp
->nrports
= 8;
2497 panelp
->ackmask
= 0xc0;
2502 ioaddr
+= EREG_BANKSIZE
;
2503 brdp
->nrports
+= panelp
->nrports
;
2504 brdp
->panels
[panelnr
++] = panelp
;
2505 if ((brdp
->brdtype
!= BRD_ECHPCI
) &&
2506 (ioaddr
>= (brdp
->ioaddr2
+ brdp
->iosize2
)))
2510 brdp
->nrpanels
= panelnr
;
2511 brdp
->nrbnks
= banknr
;
2512 if (brdp
->brdtype
== BRD_ECH
)
2513 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
2515 brdp
->state
|= BRD_FOUND
;
2516 if (request_irq(brdp
->irq
, stl_intr
, SA_SHIRQ
, name
, brdp
) != 0) {
2517 printk("STALLION: failed to register interrupt "
2518 "routine for %s irq=%d\n", name
, brdp
->irq
);
2527 /*****************************************************************************/
2530 * Initialize and configure the specified board.
2531 * Scan through all the boards in the configuration and see what we
2532 * can find. Handle EIO and the ECH boards a little differently here
2533 * since the initial search and setup is very different.
2536 static int __init
stl_brdinit(stlbrd_t
*brdp
)
2541 printk("stl_brdinit(brdp=%x)\n", (int) brdp
);
2544 switch (brdp
->brdtype
) {
2556 printk("STALLION: board=%d is unknown board type=%d\n",
2557 brdp
->brdnr
, brdp
->brdtype
);
2561 stl_brds
[brdp
->brdnr
] = brdp
;
2562 if ((brdp
->state
& BRD_FOUND
) == 0) {
2563 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2564 stl_brdnames
[brdp
->brdtype
], brdp
->brdnr
,
2565 brdp
->ioaddr1
, brdp
->irq
);
2569 for (i
= 0; (i
< STL_MAXPANELS
); i
++)
2570 if (brdp
->panels
[i
] != (stlpanel_t
*) NULL
)
2571 stl_initports(brdp
, brdp
->panels
[i
]);
2573 printk("STALLION: %s found, board=%d io=%x irq=%d "
2574 "nrpanels=%d nrports=%d\n", stl_brdnames
[brdp
->brdtype
],
2575 brdp
->brdnr
, brdp
->ioaddr1
, brdp
->irq
, brdp
->nrpanels
,
2580 /*****************************************************************************/
2583 * Find the next available board number that is free.
2586 static inline int stl_getbrdnr(void)
2590 for (i
= 0; (i
< STL_MAXBRDS
); i
++) {
2591 if (stl_brds
[i
] == (stlbrd_t
*) NULL
) {
2592 if (i
>= stl_nrbrds
)
2600 /*****************************************************************************/
2605 * We have a Stallion board. Allocate a board structure and
2606 * initialize it. Read its IO and IRQ resources from PCI
2607 * configuration space.
2610 static inline int stl_initpcibrd(int brdtype
, struct pci_dev
*devp
)
2615 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype
,
2616 devp
->bus
->number
, devp
->devfn
);
2619 if (pci_enable_device(devp
))
2621 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
2623 if ((brdp
->brdnr
= stl_getbrdnr()) < 0) {
2624 printk("STALLION: too many boards found, "
2625 "maximum supported %d\n", STL_MAXBRDS
);
2628 brdp
->brdtype
= brdtype
;
2631 * Different Stallion boards use the BAR registers in different ways,
2632 * so set up io addresses based on board type.
2635 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__
, __LINE__
,
2636 pci_resource_start(devp
, 0), pci_resource_start(devp
, 1),
2637 pci_resource_start(devp
, 2), pci_resource_start(devp
, 3), devp
->irq
);
2641 * We have all resources from the board, so let's setup the actual
2642 * board structure now.
2646 brdp
->ioaddr2
= pci_resource_start(devp
, 0);
2647 brdp
->ioaddr1
= pci_resource_start(devp
, 1);
2650 brdp
->ioaddr2
= pci_resource_start(devp
, 2);
2651 brdp
->ioaddr1
= pci_resource_start(devp
, 1);
2654 brdp
->ioaddr1
= pci_resource_start(devp
, 2);
2655 brdp
->ioaddr2
= pci_resource_start(devp
, 1);
2658 printk("STALLION: unknown PCI board type=%d\n", brdtype
);
2662 brdp
->irq
= devp
->irq
;
2668 /*****************************************************************************/
2671 * Find all Stallion PCI boards that might be installed. Initialize each
2672 * one as it is found.
2676 static inline int stl_findpcibrds(void)
2678 struct pci_dev
*dev
= NULL
;
2682 printk("stl_findpcibrds()\n");
2685 for (i
= 0; (i
< stl_nrpcibrds
); i
++)
2686 while ((dev
= pci_find_device(stl_pcibrds
[i
].vendid
,
2687 stl_pcibrds
[i
].devid
, dev
))) {
2690 * Found a device on the PCI bus that has our vendor and
2691 * device ID. Need to check now that it is really us.
2693 if ((dev
->class >> 8) == PCI_CLASS_STORAGE_IDE
)
2696 rc
= stl_initpcibrd(stl_pcibrds
[i
].brdtype
, dev
);
2706 /*****************************************************************************/
2709 * Scan through all the boards in the configuration and see what we
2710 * can find. Handle EIO and the ECH boards a little differently here
2711 * since the initial search and setup is too different.
2714 static inline int stl_initbrds(void)
2721 printk("stl_initbrds()\n");
2724 if (stl_nrbrds
> STL_MAXBRDS
) {
2725 printk("STALLION: too many boards in configuration table, "
2726 "truncating to %d\n", STL_MAXBRDS
);
2727 stl_nrbrds
= STL_MAXBRDS
;
2731 * Firstly scan the list of static boards configured. Allocate
2732 * resources and initialize the boards as found.
2734 for (i
= 0; (i
< stl_nrbrds
); i
++) {
2735 confp
= &stl_brdconf
[i
];
2736 stl_parsebrd(confp
, stl_brdsp
[i
]);
2737 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
2740 brdp
->brdtype
= confp
->brdtype
;
2741 brdp
->ioaddr1
= confp
->ioaddr1
;
2742 brdp
->ioaddr2
= confp
->ioaddr2
;
2743 brdp
->irq
= confp
->irq
;
2744 brdp
->irqtype
= confp
->irqtype
;
2749 * Find any dynamically supported boards. That is via module load
2750 * line options or auto-detected on the PCI bus.
2760 /*****************************************************************************/
2763 * Return the board stats structure to user app.
2766 static int stl_getbrdstats(combrd_t __user
*bp
)
2772 if (copy_from_user(&stl_brdstats
, bp
, sizeof(combrd_t
)))
2774 if (stl_brdstats
.brd
>= STL_MAXBRDS
)
2776 brdp
= stl_brds
[stl_brdstats
.brd
];
2777 if (brdp
== (stlbrd_t
*) NULL
)
2780 memset(&stl_brdstats
, 0, sizeof(combrd_t
));
2781 stl_brdstats
.brd
= brdp
->brdnr
;
2782 stl_brdstats
.type
= brdp
->brdtype
;
2783 stl_brdstats
.hwid
= brdp
->hwid
;
2784 stl_brdstats
.state
= brdp
->state
;
2785 stl_brdstats
.ioaddr
= brdp
->ioaddr1
;
2786 stl_brdstats
.ioaddr2
= brdp
->ioaddr2
;
2787 stl_brdstats
.irq
= brdp
->irq
;
2788 stl_brdstats
.nrpanels
= brdp
->nrpanels
;
2789 stl_brdstats
.nrports
= brdp
->nrports
;
2790 for (i
= 0; (i
< brdp
->nrpanels
); i
++) {
2791 panelp
= brdp
->panels
[i
];
2792 stl_brdstats
.panels
[i
].panel
= i
;
2793 stl_brdstats
.panels
[i
].hwid
= panelp
->hwid
;
2794 stl_brdstats
.panels
[i
].nrports
= panelp
->nrports
;
2797 return copy_to_user(bp
, &stl_brdstats
, sizeof(combrd_t
)) ? -EFAULT
: 0;
2800 /*****************************************************************************/
2803 * Resolve the referenced port number into a port struct pointer.
2806 static stlport_t
*stl_getport(int brdnr
, int panelnr
, int portnr
)
2811 if ((brdnr
< 0) || (brdnr
>= STL_MAXBRDS
))
2812 return((stlport_t
*) NULL
);
2813 brdp
= stl_brds
[brdnr
];
2814 if (brdp
== (stlbrd_t
*) NULL
)
2815 return((stlport_t
*) NULL
);
2816 if ((panelnr
< 0) || (panelnr
>= brdp
->nrpanels
))
2817 return((stlport_t
*) NULL
);
2818 panelp
= brdp
->panels
[panelnr
];
2819 if (panelp
== (stlpanel_t
*) NULL
)
2820 return((stlport_t
*) NULL
);
2821 if ((portnr
< 0) || (portnr
>= panelp
->nrports
))
2822 return((stlport_t
*) NULL
);
2823 return(panelp
->ports
[portnr
]);
2826 /*****************************************************************************/
2829 * Return the port stats structure to user app. A NULL port struct
2830 * pointer passed in means that we need to find out from the app
2831 * what port to get stats for (used through board control device).
2834 static int stl_getportstats(stlport_t
*portp
, comstats_t __user
*cp
)
2836 unsigned char *head
, *tail
;
2837 unsigned long flags
;
2840 if (copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
)))
2842 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
2844 if (portp
== (stlport_t
*) NULL
)
2848 portp
->stats
.state
= portp
->istate
;
2849 portp
->stats
.flags
= portp
->flags
;
2850 portp
->stats
.hwid
= portp
->hwid
;
2852 portp
->stats
.ttystate
= 0;
2853 portp
->stats
.cflags
= 0;
2854 portp
->stats
.iflags
= 0;
2855 portp
->stats
.oflags
= 0;
2856 portp
->stats
.lflags
= 0;
2857 portp
->stats
.rxbuffered
= 0;
2859 spin_lock_irqsave(&stallion_lock
, flags
);
2860 if (portp
->tty
!= (struct tty_struct
*) NULL
) {
2861 if (portp
->tty
->driver_data
== portp
) {
2862 portp
->stats
.ttystate
= portp
->tty
->flags
;
2863 /* No longer available as a statistic */
2864 portp
->stats
.rxbuffered
= 1; /*portp->tty->flip.count; */
2865 if (portp
->tty
->termios
!= (struct termios
*) NULL
) {
2866 portp
->stats
.cflags
= portp
->tty
->termios
->c_cflag
;
2867 portp
->stats
.iflags
= portp
->tty
->termios
->c_iflag
;
2868 portp
->stats
.oflags
= portp
->tty
->termios
->c_oflag
;
2869 portp
->stats
.lflags
= portp
->tty
->termios
->c_lflag
;
2873 spin_unlock_irqrestore(&stallion_lock
, flags
);
2875 head
= portp
->tx
.head
;
2876 tail
= portp
->tx
.tail
;
2877 portp
->stats
.txbuffered
= ((head
>= tail
) ? (head
- tail
) :
2878 (STL_TXBUFSIZE
- (tail
- head
)));
2880 portp
->stats
.signals
= (unsigned long) stl_getsignals(portp
);
2882 return copy_to_user(cp
, &portp
->stats
,
2883 sizeof(comstats_t
)) ? -EFAULT
: 0;
2886 /*****************************************************************************/
2889 * Clear the port stats structure. We also return it zeroed out...
2892 static int stl_clrportstats(stlport_t
*portp
, comstats_t __user
*cp
)
2895 if (copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
)))
2897 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
2899 if (portp
== (stlport_t
*) NULL
)
2903 memset(&portp
->stats
, 0, sizeof(comstats_t
));
2904 portp
->stats
.brd
= portp
->brdnr
;
2905 portp
->stats
.panel
= portp
->panelnr
;
2906 portp
->stats
.port
= portp
->portnr
;
2907 return copy_to_user(cp
, &portp
->stats
,
2908 sizeof(comstats_t
)) ? -EFAULT
: 0;
2911 /*****************************************************************************/
2914 * Return the entire driver ports structure to a user app.
2917 static int stl_getportstruct(stlport_t __user
*arg
)
2921 if (copy_from_user(&stl_dummyport
, arg
, sizeof(stlport_t
)))
2923 portp
= stl_getport(stl_dummyport
.brdnr
, stl_dummyport
.panelnr
,
2924 stl_dummyport
.portnr
);
2927 return copy_to_user(arg
, portp
, sizeof(stlport_t
)) ? -EFAULT
: 0;
2930 /*****************************************************************************/
2933 * Return the entire driver board structure to a user app.
2936 static int stl_getbrdstruct(stlbrd_t __user
*arg
)
2940 if (copy_from_user(&stl_dummybrd
, arg
, sizeof(stlbrd_t
)))
2942 if ((stl_dummybrd
.brdnr
< 0) || (stl_dummybrd
.brdnr
>= STL_MAXBRDS
))
2944 brdp
= stl_brds
[stl_dummybrd
.brdnr
];
2947 return copy_to_user(arg
, brdp
, sizeof(stlbrd_t
)) ? -EFAULT
: 0;
2950 /*****************************************************************************/
2953 * The "staliomem" device is also required to do some special operations
2954 * on the board and/or ports. In this driver it is mostly used for stats
2958 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
)
2961 void __user
*argp
= (void __user
*)arg
;
2964 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip
,
2965 (int) fp
, cmd
, (int) arg
);
2969 if (brdnr
>= STL_MAXBRDS
)
2974 case COM_GETPORTSTATS
:
2975 rc
= stl_getportstats(NULL
, argp
);
2977 case COM_CLRPORTSTATS
:
2978 rc
= stl_clrportstats(NULL
, argp
);
2980 case COM_GETBRDSTATS
:
2981 rc
= stl_getbrdstats(argp
);
2984 rc
= stl_getportstruct(argp
);
2987 rc
= stl_getbrdstruct(argp
);
2997 static struct tty_operations stl_ops
= {
3001 .put_char
= stl_putchar
,
3002 .flush_chars
= stl_flushchars
,
3003 .write_room
= stl_writeroom
,
3004 .chars_in_buffer
= stl_charsinbuffer
,
3006 .set_termios
= stl_settermios
,
3007 .throttle
= stl_throttle
,
3008 .unthrottle
= stl_unthrottle
,
3011 .hangup
= stl_hangup
,
3012 .flush_buffer
= stl_flushbuffer
,
3013 .break_ctl
= stl_breakctl
,
3014 .wait_until_sent
= stl_waituntilsent
,
3015 .send_xchar
= stl_sendxchar
,
3016 .read_proc
= stl_readproc
,
3017 .tiocmget
= stl_tiocmget
,
3018 .tiocmset
= stl_tiocmset
,
3021 /*****************************************************************************/
3023 static int __init
stl_init(void)
3026 printk(KERN_INFO
"%s: version %s\n", stl_drvtitle
, stl_drvversion
);
3028 spin_lock_init(&stallion_lock
);
3029 spin_lock_init(&brd_lock
);
3033 stl_serial
= alloc_tty_driver(STL_MAXBRDS
* STL_MAXPORTS
);
3038 * Set up a character driver for per board stuff. This is mainly used
3039 * to do stats ioctls on the ports.
3041 if (register_chrdev(STL_SIOMEMMAJOR
, "staliomem", &stl_fsiomem
))
3042 printk("STALLION: failed to register serial board device\n");
3044 stallion_class
= class_create(THIS_MODULE
, "staliomem");
3045 for (i
= 0; i
< 4; i
++)
3046 class_device_create(stallion_class
, NULL
,
3047 MKDEV(STL_SIOMEMMAJOR
, i
), NULL
,
3050 stl_serial
->owner
= THIS_MODULE
;
3051 stl_serial
->driver_name
= stl_drvname
;
3052 stl_serial
->name
= "ttyE";
3053 stl_serial
->major
= STL_SERIALMAJOR
;
3054 stl_serial
->minor_start
= 0;
3055 stl_serial
->type
= TTY_DRIVER_TYPE_SERIAL
;
3056 stl_serial
->subtype
= SERIAL_TYPE_NORMAL
;
3057 stl_serial
->init_termios
= stl_deftermios
;
3058 stl_serial
->flags
= TTY_DRIVER_REAL_RAW
;
3059 tty_set_operations(stl_serial
, &stl_ops
);
3061 if (tty_register_driver(stl_serial
)) {
3062 put_tty_driver(stl_serial
);
3063 printk("STALLION: failed to register serial driver\n");
3070 /*****************************************************************************/
3071 /* CD1400 HARDWARE FUNCTIONS */
3072 /*****************************************************************************/
3075 * These functions get/set/update the registers of the cd1400 UARTs.
3076 * Access to the cd1400 registers is via an address/data io port pair.
3077 * (Maybe should make this inline...)
3080 static int stl_cd1400getreg(stlport_t
*portp
, int regnr
)
3082 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3083 return inb(portp
->ioaddr
+ EREG_DATA
);
3086 static void stl_cd1400setreg(stlport_t
*portp
, int regnr
, int value
)
3088 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3089 outb(value
, portp
->ioaddr
+ EREG_DATA
);
3092 static int stl_cd1400updatereg(stlport_t
*portp
, int regnr
, int value
)
3094 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3095 if (inb(portp
->ioaddr
+ EREG_DATA
) != value
) {
3096 outb(value
, portp
->ioaddr
+ EREG_DATA
);
3102 /*****************************************************************************/
3105 * Inbitialize the UARTs in a panel. We don't care what sort of board
3106 * these ports are on - since the port io registers are almost
3107 * identical when dealing with ports.
3110 static int stl_cd1400panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
3114 int nrchips
, uartaddr
, ioaddr
;
3115 unsigned long flags
;
3118 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
3121 spin_lock_irqsave(&brd_lock
, flags
);
3122 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
3125 * Check that each chip is present and started up OK.
3128 nrchips
= panelp
->nrports
/ CD1400_PORTS
;
3129 for (i
= 0; (i
< nrchips
); i
++) {
3130 if (brdp
->brdtype
== BRD_ECHPCI
) {
3131 outb((panelp
->pagenr
+ (i
>> 1)), brdp
->ioctrl
);
3132 ioaddr
= panelp
->iobase
;
3134 ioaddr
= panelp
->iobase
+ (EREG_BANKSIZE
* (i
>> 1));
3136 uartaddr
= (i
& 0x01) ? 0x080 : 0;
3137 outb((GFRCR
+ uartaddr
), ioaddr
);
3138 outb(0, (ioaddr
+ EREG_DATA
));
3139 outb((CCR
+ uartaddr
), ioaddr
);
3140 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
3141 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
3142 outb((GFRCR
+ uartaddr
), ioaddr
);
3143 for (j
= 0; (j
< CCR_MAXWAIT
); j
++) {
3144 if ((gfrcr
= inb(ioaddr
+ EREG_DATA
)) != 0)
3147 if ((j
>= CCR_MAXWAIT
) || (gfrcr
< 0x40) || (gfrcr
> 0x60)) {
3148 printk("STALLION: cd1400 not responding, "
3149 "brd=%d panel=%d chip=%d\n",
3150 panelp
->brdnr
, panelp
->panelnr
, i
);
3153 chipmask
|= (0x1 << i
);
3154 outb((PPR
+ uartaddr
), ioaddr
);
3155 outb(PPR_SCALAR
, (ioaddr
+ EREG_DATA
));
3158 BRDDISABLE(panelp
->brdnr
);
3159 spin_unlock_irqrestore(&brd_lock
, flags
);
3163 /*****************************************************************************/
3166 * Initialize hardware specific port registers.
3169 static void stl_cd1400portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
3171 unsigned long flags
;
3173 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3174 (int) brdp
, (int) panelp
, (int) portp
);
3177 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
3178 (portp
== (stlport_t
*) NULL
))
3181 spin_lock_irqsave(&brd_lock
, flags
);
3182 portp
->ioaddr
= panelp
->iobase
+ (((brdp
->brdtype
== BRD_ECHPCI
) ||
3183 (portp
->portnr
< 8)) ? 0 : EREG_BANKSIZE
);
3184 portp
->uartaddr
= (portp
->portnr
& 0x04) << 5;
3185 portp
->pagenr
= panelp
->pagenr
+ (portp
->portnr
>> 3);
3187 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3188 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3189 stl_cd1400setreg(portp
, LIVR
, (portp
->portnr
<< 3));
3190 portp
->hwid
= stl_cd1400getreg(portp
, GFRCR
);
3191 BRDDISABLE(portp
->brdnr
);
3192 spin_unlock_irqrestore(&brd_lock
, flags
);
3195 /*****************************************************************************/
3198 * Wait for the command register to be ready. We will poll this,
3199 * since it won't usually take too long to be ready.
3202 static void stl_cd1400ccrwait(stlport_t
*portp
)
3206 for (i
= 0; (i
< CCR_MAXWAIT
); i
++) {
3207 if (stl_cd1400getreg(portp
, CCR
) == 0) {
3212 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3213 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
3216 /*****************************************************************************/
3219 * Set up the cd1400 registers for a port based on the termios port
3223 static void stl_cd1400setport(stlport_t
*portp
, struct termios
*tiosp
)
3226 unsigned long flags
;
3227 unsigned int clkdiv
, baudrate
;
3228 unsigned char cor1
, cor2
, cor3
;
3229 unsigned char cor4
, cor5
, ccr
;
3230 unsigned char srer
, sreron
, sreroff
;
3231 unsigned char mcor1
, mcor2
, rtpr
;
3232 unsigned char clk
, div
;
3248 brdp
= stl_brds
[portp
->brdnr
];
3249 if (brdp
== (stlbrd_t
*) NULL
)
3253 * Set up the RX char ignore mask with those RX error types we
3254 * can ignore. We can get the cd1400 to help us out a little here,
3255 * it will ignore parity errors and breaks for us.
3257 portp
->rxignoremsk
= 0;
3258 if (tiosp
->c_iflag
& IGNPAR
) {
3259 portp
->rxignoremsk
|= (ST_PARITY
| ST_FRAMING
| ST_OVERRUN
);
3260 cor1
|= COR1_PARIGNORE
;
3262 if (tiosp
->c_iflag
& IGNBRK
) {
3263 portp
->rxignoremsk
|= ST_BREAK
;
3264 cor4
|= COR4_IGNBRK
;
3267 portp
->rxmarkmsk
= ST_OVERRUN
;
3268 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
3269 portp
->rxmarkmsk
|= (ST_PARITY
| ST_FRAMING
);
3270 if (tiosp
->c_iflag
& BRKINT
)
3271 portp
->rxmarkmsk
|= ST_BREAK
;
3274 * Go through the char size, parity and stop bits and set all the
3275 * option register appropriately.
3277 switch (tiosp
->c_cflag
& CSIZE
) {
3292 if (tiosp
->c_cflag
& CSTOPB
)
3297 if (tiosp
->c_cflag
& PARENB
) {
3298 if (tiosp
->c_cflag
& PARODD
)
3299 cor1
|= (COR1_PARENB
| COR1_PARODD
);
3301 cor1
|= (COR1_PARENB
| COR1_PAREVEN
);
3303 cor1
|= COR1_PARNONE
;
3307 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3308 * space for hardware flow control and the like. This should be set to
3309 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3310 * really be based on VTIME.
3312 cor3
|= FIFO_RXTHRESHOLD
;
3316 * Calculate the baud rate timers. For now we will just assume that
3317 * the input and output baud are the same. Could have used a baud
3318 * table here, but this way we can generate virtually any baud rate
3321 baudrate
= tiosp
->c_cflag
& CBAUD
;
3322 if (baudrate
& CBAUDEX
) {
3323 baudrate
&= ~CBAUDEX
;
3324 if ((baudrate
< 1) || (baudrate
> 4))
3325 tiosp
->c_cflag
&= ~CBAUDEX
;
3329 baudrate
= stl_baudrates
[baudrate
];
3330 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
3331 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3333 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3335 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3337 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3339 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
3340 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
3342 if (baudrate
> STL_CD1400MAXBAUD
)
3343 baudrate
= STL_CD1400MAXBAUD
;
3346 for (clk
= 0; (clk
< CD1400_NUMCLKS
); clk
++) {
3347 clkdiv
= ((portp
->clk
/ stl_cd1400clkdivs
[clk
]) / baudrate
);
3351 div
= (unsigned char) clkdiv
;
3355 * Check what form of modem signaling is required and set it up.
3357 if ((tiosp
->c_cflag
& CLOCAL
) == 0) {
3360 sreron
|= SRER_MODEM
;
3361 portp
->flags
|= ASYNC_CHECK_CD
;
3363 portp
->flags
&= ~ASYNC_CHECK_CD
;
3367 * Setup cd1400 enhanced modes if we can. In particular we want to
3368 * handle as much of the flow control as possible automatically. As
3369 * well as saving a few CPU cycles it will also greatly improve flow
3370 * control reliability.
3372 if (tiosp
->c_iflag
& IXON
) {
3375 if (tiosp
->c_iflag
& IXANY
)
3379 if (tiosp
->c_cflag
& CRTSCTS
) {
3381 mcor1
|= FIFO_RTSTHRESHOLD
;
3385 * All cd1400 register values calculated so go through and set
3390 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3391 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
3392 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3393 cor1
, cor2
, cor3
, cor4
, cor5
);
3394 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3395 mcor1
, mcor2
, rtpr
, sreron
, sreroff
);
3396 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk
, div
, clk
, div
);
3397 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3398 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
3399 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
3402 spin_lock_irqsave(&brd_lock
, flags
);
3403 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3404 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x3));
3405 srer
= stl_cd1400getreg(portp
, SRER
);
3406 stl_cd1400setreg(portp
, SRER
, 0);
3407 if (stl_cd1400updatereg(portp
, COR1
, cor1
))
3409 if (stl_cd1400updatereg(portp
, COR2
, cor2
))
3411 if (stl_cd1400updatereg(portp
, COR3
, cor3
))
3414 stl_cd1400ccrwait(portp
);
3415 stl_cd1400setreg(portp
, CCR
, CCR_CORCHANGE
);
3417 stl_cd1400setreg(portp
, COR4
, cor4
);
3418 stl_cd1400setreg(portp
, COR5
, cor5
);
3419 stl_cd1400setreg(portp
, MCOR1
, mcor1
);
3420 stl_cd1400setreg(portp
, MCOR2
, mcor2
);
3422 stl_cd1400setreg(portp
, TCOR
, clk
);
3423 stl_cd1400setreg(portp
, TBPR
, div
);
3424 stl_cd1400setreg(portp
, RCOR
, clk
);
3425 stl_cd1400setreg(portp
, RBPR
, div
);
3427 stl_cd1400setreg(portp
, SCHR1
, tiosp
->c_cc
[VSTART
]);
3428 stl_cd1400setreg(portp
, SCHR2
, tiosp
->c_cc
[VSTOP
]);
3429 stl_cd1400setreg(portp
, SCHR3
, tiosp
->c_cc
[VSTART
]);
3430 stl_cd1400setreg(portp
, SCHR4
, tiosp
->c_cc
[VSTOP
]);
3431 stl_cd1400setreg(portp
, RTPR
, rtpr
);
3432 mcor1
= stl_cd1400getreg(portp
, MSVR1
);
3433 if (mcor1
& MSVR1_DCD
)
3434 portp
->sigs
|= TIOCM_CD
;
3436 portp
->sigs
&= ~TIOCM_CD
;
3437 stl_cd1400setreg(portp
, SRER
, ((srer
& ~sreroff
) | sreron
));
3438 BRDDISABLE(portp
->brdnr
);
3439 spin_unlock_irqrestore(&brd_lock
, flags
);
3442 /*****************************************************************************/
3445 * Set the state of the DTR and RTS signals.
3448 static void stl_cd1400setsignals(stlport_t
*portp
, int dtr
, int rts
)
3450 unsigned char msvr1
, msvr2
;
3451 unsigned long flags
;
3454 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3455 (int) portp
, dtr
, rts
);
3465 spin_lock_irqsave(&brd_lock
, flags
);
3466 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3467 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3469 stl_cd1400setreg(portp
, MSVR2
, msvr2
);
3471 stl_cd1400setreg(portp
, MSVR1
, msvr1
);
3472 BRDDISABLE(portp
->brdnr
);
3473 spin_unlock_irqrestore(&brd_lock
, flags
);
3476 /*****************************************************************************/
3479 * Return the state of the signals.
3482 static int stl_cd1400getsignals(stlport_t
*portp
)
3484 unsigned char msvr1
, msvr2
;
3485 unsigned long flags
;
3489 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp
);
3492 spin_lock_irqsave(&brd_lock
, flags
);
3493 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3494 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3495 msvr1
= stl_cd1400getreg(portp
, MSVR1
);
3496 msvr2
= stl_cd1400getreg(portp
, MSVR2
);
3497 BRDDISABLE(portp
->brdnr
);
3498 spin_unlock_irqrestore(&brd_lock
, flags
);
3501 sigs
|= (msvr1
& MSVR1_DCD
) ? TIOCM_CD
: 0;
3502 sigs
|= (msvr1
& MSVR1_CTS
) ? TIOCM_CTS
: 0;
3503 sigs
|= (msvr1
& MSVR1_DTR
) ? TIOCM_DTR
: 0;
3504 sigs
|= (msvr2
& MSVR2_RTS
) ? TIOCM_RTS
: 0;
3506 sigs
|= (msvr1
& MSVR1_RI
) ? TIOCM_RI
: 0;
3507 sigs
|= (msvr1
& MSVR1_DSR
) ? TIOCM_DSR
: 0;
3514 /*****************************************************************************/
3517 * Enable/Disable the Transmitter and/or Receiver.
3520 static void stl_cd1400enablerxtx(stlport_t
*portp
, int rx
, int tx
)
3523 unsigned long flags
;
3526 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3527 (int) portp
, rx
, tx
);
3532 ccr
|= CCR_TXDISABLE
;
3534 ccr
|= CCR_TXENABLE
;
3536 ccr
|= CCR_RXDISABLE
;
3538 ccr
|= CCR_RXENABLE
;
3540 spin_lock_irqsave(&brd_lock
, flags
);
3541 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3542 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3543 stl_cd1400ccrwait(portp
);
3544 stl_cd1400setreg(portp
, CCR
, ccr
);
3545 stl_cd1400ccrwait(portp
);
3546 BRDDISABLE(portp
->brdnr
);
3547 spin_unlock_irqrestore(&brd_lock
, flags
);
3550 /*****************************************************************************/
3553 * Start/stop the Transmitter and/or Receiver.
3556 static void stl_cd1400startrxtx(stlport_t
*portp
, int rx
, int tx
)
3558 unsigned char sreron
, sreroff
;
3559 unsigned long flags
;
3562 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3563 (int) portp
, rx
, tx
);
3569 sreroff
|= (SRER_TXDATA
| SRER_TXEMPTY
);
3571 sreron
|= SRER_TXDATA
;
3573 sreron
|= SRER_TXEMPTY
;
3575 sreroff
|= SRER_RXDATA
;
3577 sreron
|= SRER_RXDATA
;
3579 spin_lock_irqsave(&brd_lock
, flags
);
3580 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3581 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3582 stl_cd1400setreg(portp
, SRER
,
3583 ((stl_cd1400getreg(portp
, SRER
) & ~sreroff
) | sreron
));
3584 BRDDISABLE(portp
->brdnr
);
3586 set_bit(ASYI_TXBUSY
, &portp
->istate
);
3587 spin_unlock_irqrestore(&brd_lock
, flags
);
3590 /*****************************************************************************/
3593 * Disable all interrupts from this port.
3596 static void stl_cd1400disableintrs(stlport_t
*portp
)
3598 unsigned long flags
;
3601 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp
);
3603 spin_lock_irqsave(&brd_lock
, flags
);
3604 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3605 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3606 stl_cd1400setreg(portp
, SRER
, 0);
3607 BRDDISABLE(portp
->brdnr
);
3608 spin_unlock_irqrestore(&brd_lock
, flags
);
3611 /*****************************************************************************/
3613 static void stl_cd1400sendbreak(stlport_t
*portp
, int len
)
3615 unsigned long flags
;
3618 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
3621 spin_lock_irqsave(&brd_lock
, flags
);
3622 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3623 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3624 stl_cd1400setreg(portp
, SRER
,
3625 ((stl_cd1400getreg(portp
, SRER
) & ~SRER_TXDATA
) |
3627 BRDDISABLE(portp
->brdnr
);
3628 portp
->brklen
= len
;
3630 portp
->stats
.txbreaks
++;
3631 spin_unlock_irqrestore(&brd_lock
, flags
);
3634 /*****************************************************************************/
3637 * Take flow control actions...
3640 static void stl_cd1400flowctrl(stlport_t
*portp
, int state
)
3642 struct tty_struct
*tty
;
3643 unsigned long flags
;
3646 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
3649 if (portp
== (stlport_t
*) NULL
)
3652 if (tty
== (struct tty_struct
*) NULL
)
3655 spin_lock_irqsave(&brd_lock
, flags
);
3656 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3657 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3660 if (tty
->termios
->c_iflag
& IXOFF
) {
3661 stl_cd1400ccrwait(portp
);
3662 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3663 portp
->stats
.rxxon
++;
3664 stl_cd1400ccrwait(portp
);
3667 * Question: should we return RTS to what it was before? It may
3668 * have been set by an ioctl... Suppose not, since if you have
3669 * hardware flow control set then it is pretty silly to go and
3670 * set the RTS line by hand.
3672 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3673 stl_cd1400setreg(portp
, MCOR1
,
3674 (stl_cd1400getreg(portp
, MCOR1
) |
3675 FIFO_RTSTHRESHOLD
));
3676 stl_cd1400setreg(portp
, MSVR2
, MSVR2_RTS
);
3677 portp
->stats
.rxrtson
++;
3680 if (tty
->termios
->c_iflag
& IXOFF
) {
3681 stl_cd1400ccrwait(portp
);
3682 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3683 portp
->stats
.rxxoff
++;
3684 stl_cd1400ccrwait(portp
);
3686 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3687 stl_cd1400setreg(portp
, MCOR1
,
3688 (stl_cd1400getreg(portp
, MCOR1
) & 0xf0));
3689 stl_cd1400setreg(portp
, MSVR2
, 0);
3690 portp
->stats
.rxrtsoff
++;
3694 BRDDISABLE(portp
->brdnr
);
3695 spin_unlock_irqrestore(&brd_lock
, flags
);
3698 /*****************************************************************************/
3701 * Send a flow control character...
3704 static void stl_cd1400sendflow(stlport_t
*portp
, int state
)
3706 struct tty_struct
*tty
;
3707 unsigned long flags
;
3710 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
3713 if (portp
== (stlport_t
*) NULL
)
3716 if (tty
== (struct tty_struct
*) NULL
)
3719 spin_lock_irqsave(&brd_lock
, flags
);
3720 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3721 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3723 stl_cd1400ccrwait(portp
);
3724 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3725 portp
->stats
.rxxon
++;
3726 stl_cd1400ccrwait(portp
);
3728 stl_cd1400ccrwait(portp
);
3729 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3730 portp
->stats
.rxxoff
++;
3731 stl_cd1400ccrwait(portp
);
3733 BRDDISABLE(portp
->brdnr
);
3734 spin_unlock_irqrestore(&brd_lock
, flags
);
3737 /*****************************************************************************/
3739 static void stl_cd1400flush(stlport_t
*portp
)
3741 unsigned long flags
;
3744 printk("stl_cd1400flush(portp=%x)\n", (int) portp
);
3747 if (portp
== (stlport_t
*) NULL
)
3750 spin_lock_irqsave(&brd_lock
, flags
);
3751 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3752 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3753 stl_cd1400ccrwait(portp
);
3754 stl_cd1400setreg(portp
, CCR
, CCR_TXFLUSHFIFO
);
3755 stl_cd1400ccrwait(portp
);
3756 portp
->tx
.tail
= portp
->tx
.head
;
3757 BRDDISABLE(portp
->brdnr
);
3758 spin_unlock_irqrestore(&brd_lock
, flags
);
3761 /*****************************************************************************/
3764 * Return the current state of data flow on this port. This is only
3765 * really interresting when determining if data has fully completed
3766 * transmission or not... This is easy for the cd1400, it accurately
3767 * maintains the busy port flag.
3770 static int stl_cd1400datastate(stlport_t
*portp
)
3773 printk("stl_cd1400datastate(portp=%x)\n", (int) portp
);
3776 if (portp
== (stlport_t
*) NULL
)
3779 return test_bit(ASYI_TXBUSY
, &portp
->istate
) ? 1 : 0;
3782 /*****************************************************************************/
3785 * Interrupt service routine for cd1400 EasyIO boards.
3788 static void stl_cd1400eiointr(stlpanel_t
*panelp
, unsigned int iobase
)
3790 unsigned char svrtype
;
3793 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3794 (int) panelp
, iobase
);
3797 spin_lock(&brd_lock
);
3799 svrtype
= inb(iobase
+ EREG_DATA
);
3800 if (panelp
->nrports
> 4) {
3801 outb((SVRR
+ 0x80), iobase
);
3802 svrtype
|= inb(iobase
+ EREG_DATA
);
3805 if (svrtype
& SVRR_RX
)
3806 stl_cd1400rxisr(panelp
, iobase
);
3807 else if (svrtype
& SVRR_TX
)
3808 stl_cd1400txisr(panelp
, iobase
);
3809 else if (svrtype
& SVRR_MDM
)
3810 stl_cd1400mdmisr(panelp
, iobase
);
3812 spin_unlock(&brd_lock
);
3815 /*****************************************************************************/
3818 * Interrupt service routine for cd1400 panels.
3821 static void stl_cd1400echintr(stlpanel_t
*panelp
, unsigned int iobase
)
3823 unsigned char svrtype
;
3826 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp
,
3831 svrtype
= inb(iobase
+ EREG_DATA
);
3832 outb((SVRR
+ 0x80), iobase
);
3833 svrtype
|= inb(iobase
+ EREG_DATA
);
3834 if (svrtype
& SVRR_RX
)
3835 stl_cd1400rxisr(panelp
, iobase
);
3836 else if (svrtype
& SVRR_TX
)
3837 stl_cd1400txisr(panelp
, iobase
);
3838 else if (svrtype
& SVRR_MDM
)
3839 stl_cd1400mdmisr(panelp
, iobase
);
3843 /*****************************************************************************/
3846 * Unfortunately we need to handle breaks in the TX data stream, since
3847 * this is the only way to generate them on the cd1400.
3850 static inline int stl_cd1400breakisr(stlport_t
*portp
, int ioaddr
)
3852 if (portp
->brklen
== 1) {
3853 outb((COR2
+ portp
->uartaddr
), ioaddr
);
3854 outb((inb(ioaddr
+ EREG_DATA
) | COR2_ETC
),
3855 (ioaddr
+ EREG_DATA
));
3856 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3857 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
3858 outb(ETC_STARTBREAK
, (ioaddr
+ EREG_DATA
));
3859 outb((SRER
+ portp
->uartaddr
), ioaddr
);
3860 outb((inb(ioaddr
+ EREG_DATA
) & ~(SRER_TXDATA
| SRER_TXEMPTY
)),
3861 (ioaddr
+ EREG_DATA
));
3863 } else if (portp
->brklen
> 1) {
3864 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3865 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
3866 outb(ETC_STOPBREAK
, (ioaddr
+ EREG_DATA
));
3870 outb((COR2
+ portp
->uartaddr
), ioaddr
);
3871 outb((inb(ioaddr
+ EREG_DATA
) & ~COR2_ETC
),
3872 (ioaddr
+ EREG_DATA
));
3878 /*****************************************************************************/
3881 * Transmit interrupt handler. This has gotta be fast! Handling TX
3882 * chars is pretty simple, stuff as many as possible from the TX buffer
3883 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3884 * are embedded as commands in the data stream. Oh no, had to use a goto!
3885 * This could be optimized more, will do when I get time...
3886 * In practice it is possible that interrupts are enabled but that the
3887 * port has been hung up. Need to handle not having any TX buffer here,
3888 * this is done by using the side effect that head and tail will also
3889 * be NULL if the buffer has been freed.
3892 static void stl_cd1400txisr(stlpanel_t
*panelp
, int ioaddr
)
3897 unsigned char ioack
, srer
;
3900 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
3903 ioack
= inb(ioaddr
+ EREG_TXACK
);
3904 if (((ioack
& panelp
->ackmask
) != 0) ||
3905 ((ioack
& ACK_TYPMASK
) != ACK_TYPTX
)) {
3906 printk("STALLION: bad TX interrupt ack value=%x\n", ioack
);
3909 portp
= panelp
->ports
[(ioack
>> 3)];
3912 * Unfortunately we need to handle breaks in the data stream, since
3913 * this is the only way to generate them on the cd1400. Do it now if
3914 * a break is to be sent.
3916 if (portp
->brklen
!= 0)
3917 if (stl_cd1400breakisr(portp
, ioaddr
))
3920 head
= portp
->tx
.head
;
3921 tail
= portp
->tx
.tail
;
3922 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
3923 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
3924 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
3925 set_bit(ASYI_TXLOW
, &portp
->istate
);
3926 schedule_work(&portp
->tqueue
);
3930 outb((SRER
+ portp
->uartaddr
), ioaddr
);
3931 srer
= inb(ioaddr
+ EREG_DATA
);
3932 if (srer
& SRER_TXDATA
) {
3933 srer
= (srer
& ~SRER_TXDATA
) | SRER_TXEMPTY
;
3935 srer
&= ~(SRER_TXDATA
| SRER_TXEMPTY
);
3936 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
3938 outb(srer
, (ioaddr
+ EREG_DATA
));
3940 len
= MIN(len
, CD1400_TXFIFOSIZE
);
3941 portp
->stats
.txtotal
+= len
;
3942 stlen
= MIN(len
, ((portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
));
3943 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3944 outsb((ioaddr
+ EREG_DATA
), tail
, stlen
);
3947 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
3948 tail
= portp
->tx
.buf
;
3950 outsb((ioaddr
+ EREG_DATA
), tail
, len
);
3953 portp
->tx
.tail
= tail
;
3957 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
3958 outb(0, (ioaddr
+ EREG_DATA
));
3961 /*****************************************************************************/
3964 * Receive character interrupt handler. Determine if we have good chars
3965 * or bad chars and then process appropriately. Good chars are easy
3966 * just shove the lot into the RX buffer and set all status byte to 0.
3967 * If a bad RX char then process as required. This routine needs to be
3968 * fast! In practice it is possible that we get an interrupt on a port
3969 * that is closed. This can happen on hangups - since they completely
3970 * shutdown a port not in user context. Need to handle this case.
3973 static void stl_cd1400rxisr(stlpanel_t
*panelp
, int ioaddr
)
3976 struct tty_struct
*tty
;
3977 unsigned int ioack
, len
, buflen
;
3978 unsigned char status
;
3982 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
3985 ioack
= inb(ioaddr
+ EREG_RXACK
);
3986 if ((ioack
& panelp
->ackmask
) != 0) {
3987 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
3990 portp
= panelp
->ports
[(ioack
>> 3)];
3993 if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXGOOD
) {
3994 outb((RDCR
+ portp
->uartaddr
), ioaddr
);
3995 len
= inb(ioaddr
+ EREG_DATA
);
3996 if (tty
== NULL
|| (buflen
= tty_buffer_request_room(tty
, len
)) == 0) {
3997 len
= MIN(len
, sizeof(stl_unwanted
));
3998 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
3999 insb((ioaddr
+ EREG_DATA
), &stl_unwanted
[0], len
);
4000 portp
->stats
.rxlost
+= len
;
4001 portp
->stats
.rxtotal
+= len
;
4003 len
= MIN(len
, buflen
);
4006 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4007 tty_prepare_flip_string(tty
, &ptr
, len
);
4008 insb((ioaddr
+ EREG_DATA
), ptr
, len
);
4009 tty_schedule_flip(tty
);
4010 portp
->stats
.rxtotal
+= len
;
4013 } else if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXBAD
) {
4014 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4015 status
= inb(ioaddr
+ EREG_DATA
);
4016 ch
= inb(ioaddr
+ EREG_DATA
);
4017 if (status
& ST_PARITY
)
4018 portp
->stats
.rxparity
++;
4019 if (status
& ST_FRAMING
)
4020 portp
->stats
.rxframing
++;
4021 if (status
& ST_OVERRUN
)
4022 portp
->stats
.rxoverrun
++;
4023 if (status
& ST_BREAK
)
4024 portp
->stats
.rxbreaks
++;
4025 if (status
& ST_SCHARMASK
) {
4026 if ((status
& ST_SCHARMASK
) == ST_SCHAR1
)
4027 portp
->stats
.txxon
++;
4028 if ((status
& ST_SCHARMASK
) == ST_SCHAR2
)
4029 portp
->stats
.txxoff
++;
4032 if (tty
!= NULL
&& (portp
->rxignoremsk
& status
) == 0) {
4033 if (portp
->rxmarkmsk
& status
) {
4034 if (status
& ST_BREAK
) {
4036 if (portp
->flags
& ASYNC_SAK
) {
4038 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4040 } else if (status
& ST_PARITY
) {
4041 status
= TTY_PARITY
;
4042 } else if (status
& ST_FRAMING
) {
4044 } else if(status
& ST_OVERRUN
) {
4045 status
= TTY_OVERRUN
;
4052 tty_insert_flip_char(tty
, ch
, status
);
4053 tty_schedule_flip(tty
);
4056 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
4061 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4062 outb(0, (ioaddr
+ EREG_DATA
));
4065 /*****************************************************************************/
4068 * Modem interrupt handler. The is called when the modem signal line
4069 * (DCD) has changed state. Leave most of the work to the off-level
4070 * processing routine.
4073 static void stl_cd1400mdmisr(stlpanel_t
*panelp
, int ioaddr
)
4080 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp
);
4083 ioack
= inb(ioaddr
+ EREG_MDACK
);
4084 if (((ioack
& panelp
->ackmask
) != 0) ||
4085 ((ioack
& ACK_TYPMASK
) != ACK_TYPMDM
)) {
4086 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack
);
4089 portp
= panelp
->ports
[(ioack
>> 3)];
4091 outb((MISR
+ portp
->uartaddr
), ioaddr
);
4092 misr
= inb(ioaddr
+ EREG_DATA
);
4093 if (misr
& MISR_DCD
) {
4094 set_bit(ASYI_DCDCHANGE
, &portp
->istate
);
4095 schedule_work(&portp
->tqueue
);
4096 portp
->stats
.modem
++;
4099 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4100 outb(0, (ioaddr
+ EREG_DATA
));
4103 /*****************************************************************************/
4104 /* SC26198 HARDWARE FUNCTIONS */
4105 /*****************************************************************************/
4108 * These functions get/set/update the registers of the sc26198 UARTs.
4109 * Access to the sc26198 registers is via an address/data io port pair.
4110 * (Maybe should make this inline...)
4113 static int stl_sc26198getreg(stlport_t
*portp
, int regnr
)
4115 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4116 return inb(portp
->ioaddr
+ XP_DATA
);
4119 static void stl_sc26198setreg(stlport_t
*portp
, int regnr
, int value
)
4121 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4122 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4125 static int stl_sc26198updatereg(stlport_t
*portp
, int regnr
, int value
)
4127 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4128 if (inb(portp
->ioaddr
+ XP_DATA
) != value
) {
4129 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4135 /*****************************************************************************/
4138 * Functions to get and set the sc26198 global registers.
4141 static int stl_sc26198getglobreg(stlport_t
*portp
, int regnr
)
4143 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
4144 return inb(portp
->ioaddr
+ XP_DATA
);
4148 static void stl_sc26198setglobreg(stlport_t
*portp
, int regnr
, int value
)
4150 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
4151 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4155 /*****************************************************************************/
4158 * Inbitialize the UARTs in a panel. We don't care what sort of board
4159 * these ports are on - since the port io registers are almost
4160 * identical when dealing with ports.
4163 static int stl_sc26198panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
4166 int nrchips
, ioaddr
;
4169 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4170 (int) brdp
, (int) panelp
);
4173 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
4176 * Check that each chip is present and started up OK.
4179 nrchips
= (panelp
->nrports
+ 4) / SC26198_PORTS
;
4180 if (brdp
->brdtype
== BRD_ECHPCI
)
4181 outb(panelp
->pagenr
, brdp
->ioctrl
);
4183 for (i
= 0; (i
< nrchips
); i
++) {
4184 ioaddr
= panelp
->iobase
+ (i
* 4);
4185 outb(SCCR
, (ioaddr
+ XP_ADDR
));
4186 outb(CR_RESETALL
, (ioaddr
+ XP_DATA
));
4187 outb(TSTR
, (ioaddr
+ XP_ADDR
));
4188 if (inb(ioaddr
+ XP_DATA
) != 0) {
4189 printk("STALLION: sc26198 not responding, "
4190 "brd=%d panel=%d chip=%d\n",
4191 panelp
->brdnr
, panelp
->panelnr
, i
);
4194 chipmask
|= (0x1 << i
);
4195 outb(GCCR
, (ioaddr
+ XP_ADDR
));
4196 outb(GCCR_IVRTYPCHANACK
, (ioaddr
+ XP_DATA
));
4197 outb(WDTRCR
, (ioaddr
+ XP_ADDR
));
4198 outb(0xff, (ioaddr
+ XP_DATA
));
4201 BRDDISABLE(panelp
->brdnr
);
4205 /*****************************************************************************/
4208 * Initialize hardware specific port registers.
4211 static void stl_sc26198portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
4214 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4215 (int) brdp
, (int) panelp
, (int) portp
);
4218 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
4219 (portp
== (stlport_t
*) NULL
))
4222 portp
->ioaddr
= panelp
->iobase
+ ((portp
->portnr
< 8) ? 0 : 4);
4223 portp
->uartaddr
= (portp
->portnr
& 0x07) << 4;
4224 portp
->pagenr
= panelp
->pagenr
;
4227 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4228 stl_sc26198setreg(portp
, IOPCR
, IOPCR_SETSIGS
);
4229 BRDDISABLE(portp
->brdnr
);
4232 /*****************************************************************************/
4235 * Set up the sc26198 registers for a port based on the termios port
4239 static void stl_sc26198setport(stlport_t
*portp
, struct termios
*tiosp
)
4242 unsigned long flags
;
4243 unsigned int baudrate
;
4244 unsigned char mr0
, mr1
, mr2
, clk
;
4245 unsigned char imron
, imroff
, iopr
, ipr
;
4255 brdp
= stl_brds
[portp
->brdnr
];
4256 if (brdp
== (stlbrd_t
*) NULL
)
4260 * Set up the RX char ignore mask with those RX error types we
4263 portp
->rxignoremsk
= 0;
4264 if (tiosp
->c_iflag
& IGNPAR
)
4265 portp
->rxignoremsk
|= (SR_RXPARITY
| SR_RXFRAMING
|
4267 if (tiosp
->c_iflag
& IGNBRK
)
4268 portp
->rxignoremsk
|= SR_RXBREAK
;
4270 portp
->rxmarkmsk
= SR_RXOVERRUN
;
4271 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
4272 portp
->rxmarkmsk
|= (SR_RXPARITY
| SR_RXFRAMING
);
4273 if (tiosp
->c_iflag
& BRKINT
)
4274 portp
->rxmarkmsk
|= SR_RXBREAK
;
4277 * Go through the char size, parity and stop bits and set all the
4278 * option register appropriately.
4280 switch (tiosp
->c_cflag
& CSIZE
) {
4295 if (tiosp
->c_cflag
& CSTOPB
)
4300 if (tiosp
->c_cflag
& PARENB
) {
4301 if (tiosp
->c_cflag
& PARODD
)
4302 mr1
|= (MR1_PARENB
| MR1_PARODD
);
4304 mr1
|= (MR1_PARENB
| MR1_PAREVEN
);
4309 mr1
|= MR1_ERRBLOCK
;
4312 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4313 * space for hardware flow control and the like. This should be set to
4316 mr2
|= MR2_RXFIFOHALF
;
4319 * Calculate the baud rate timers. For now we will just assume that
4320 * the input and output baud are the same. The sc26198 has a fixed
4321 * baud rate table, so only discrete baud rates possible.
4323 baudrate
= tiosp
->c_cflag
& CBAUD
;
4324 if (baudrate
& CBAUDEX
) {
4325 baudrate
&= ~CBAUDEX
;
4326 if ((baudrate
< 1) || (baudrate
> 4))
4327 tiosp
->c_cflag
&= ~CBAUDEX
;
4331 baudrate
= stl_baudrates
[baudrate
];
4332 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
4333 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
4335 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
4337 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
4339 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
4341 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
4342 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
4344 if (baudrate
> STL_SC26198MAXBAUD
)
4345 baudrate
= STL_SC26198MAXBAUD
;
4348 for (clk
= 0; (clk
< SC26198_NRBAUDS
); clk
++) {
4349 if (baudrate
<= sc26198_baudtable
[clk
])
4355 * Check what form of modem signaling is required and set it up.
4357 if (tiosp
->c_cflag
& CLOCAL
) {
4358 portp
->flags
&= ~ASYNC_CHECK_CD
;
4360 iopr
|= IOPR_DCDCOS
;
4362 portp
->flags
|= ASYNC_CHECK_CD
;
4366 * Setup sc26198 enhanced modes if we can. In particular we want to
4367 * handle as much of the flow control as possible automatically. As
4368 * well as saving a few CPU cycles it will also greatly improve flow
4369 * control reliability.
4371 if (tiosp
->c_iflag
& IXON
) {
4372 mr0
|= MR0_SWFTX
| MR0_SWFT
;
4373 imron
|= IR_XONXOFF
;
4375 imroff
|= IR_XONXOFF
;
4377 if (tiosp
->c_iflag
& IXOFF
)
4380 if (tiosp
->c_cflag
& CRTSCTS
) {
4386 * All sc26198 register values calculated so go through and set
4391 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4392 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
4393 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0
, mr1
, mr2
, clk
);
4394 printk(" iopr=%x imron=%x imroff=%x\n", iopr
, imron
, imroff
);
4395 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4396 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
4397 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
4400 spin_lock_irqsave(&brd_lock
, flags
);
4401 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4402 stl_sc26198setreg(portp
, IMR
, 0);
4403 stl_sc26198updatereg(portp
, MR0
, mr0
);
4404 stl_sc26198updatereg(portp
, MR1
, mr1
);
4405 stl_sc26198setreg(portp
, SCCR
, CR_RXERRBLOCK
);
4406 stl_sc26198updatereg(portp
, MR2
, mr2
);
4407 stl_sc26198updatereg(portp
, IOPIOR
,
4408 ((stl_sc26198getreg(portp
, IOPIOR
) & ~IPR_CHANGEMASK
) | iopr
));
4411 stl_sc26198setreg(portp
, TXCSR
, clk
);
4412 stl_sc26198setreg(portp
, RXCSR
, clk
);
4415 stl_sc26198setreg(portp
, XONCR
, tiosp
->c_cc
[VSTART
]);
4416 stl_sc26198setreg(portp
, XOFFCR
, tiosp
->c_cc
[VSTOP
]);
4418 ipr
= stl_sc26198getreg(portp
, IPR
);
4420 portp
->sigs
&= ~TIOCM_CD
;
4422 portp
->sigs
|= TIOCM_CD
;
4424 portp
->imr
= (portp
->imr
& ~imroff
) | imron
;
4425 stl_sc26198setreg(portp
, IMR
, portp
->imr
);
4426 BRDDISABLE(portp
->brdnr
);
4427 spin_unlock_irqrestore(&brd_lock
, flags
);
4430 /*****************************************************************************/
4433 * Set the state of the DTR and RTS signals.
4436 static void stl_sc26198setsignals(stlport_t
*portp
, int dtr
, int rts
)
4438 unsigned char iopioron
, iopioroff
;
4439 unsigned long flags
;
4442 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4443 (int) portp
, dtr
, rts
);
4449 iopioroff
|= IPR_DTR
;
4451 iopioron
|= IPR_DTR
;
4453 iopioroff
|= IPR_RTS
;
4455 iopioron
|= IPR_RTS
;
4457 spin_lock_irqsave(&brd_lock
, flags
);
4458 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4459 stl_sc26198setreg(portp
, IOPIOR
,
4460 ((stl_sc26198getreg(portp
, IOPIOR
) & ~iopioroff
) | iopioron
));
4461 BRDDISABLE(portp
->brdnr
);
4462 spin_unlock_irqrestore(&brd_lock
, flags
);
4465 /*****************************************************************************/
4468 * Return the state of the signals.
4471 static int stl_sc26198getsignals(stlport_t
*portp
)
4474 unsigned long flags
;
4478 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp
);
4481 spin_lock_irqsave(&brd_lock
, flags
);
4482 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4483 ipr
= stl_sc26198getreg(portp
, IPR
);
4484 BRDDISABLE(portp
->brdnr
);
4485 spin_unlock_irqrestore(&brd_lock
, flags
);
4488 sigs
|= (ipr
& IPR_DCD
) ? 0 : TIOCM_CD
;
4489 sigs
|= (ipr
& IPR_CTS
) ? 0 : TIOCM_CTS
;
4490 sigs
|= (ipr
& IPR_DTR
) ? 0: TIOCM_DTR
;
4491 sigs
|= (ipr
& IPR_RTS
) ? 0: TIOCM_RTS
;
4496 /*****************************************************************************/
4499 * Enable/Disable the Transmitter and/or Receiver.
4502 static void stl_sc26198enablerxtx(stlport_t
*portp
, int rx
, int tx
)
4505 unsigned long flags
;
4508 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4509 (int) portp
, rx
, tx
);
4512 ccr
= portp
->crenable
;
4514 ccr
&= ~CR_TXENABLE
;
4518 ccr
&= ~CR_RXENABLE
;
4522 spin_lock_irqsave(&brd_lock
, flags
);
4523 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4524 stl_sc26198setreg(portp
, SCCR
, ccr
);
4525 BRDDISABLE(portp
->brdnr
);
4526 portp
->crenable
= ccr
;
4527 spin_unlock_irqrestore(&brd_lock
, flags
);
4530 /*****************************************************************************/
4533 * Start/stop the Transmitter and/or Receiver.
4536 static void stl_sc26198startrxtx(stlport_t
*portp
, int rx
, int tx
)
4539 unsigned long flags
;
4542 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4543 (int) portp
, rx
, tx
);
4552 imr
&= ~(IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
);
4554 imr
|= IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
;
4556 spin_lock_irqsave(&brd_lock
, flags
);
4557 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4558 stl_sc26198setreg(portp
, IMR
, imr
);
4559 BRDDISABLE(portp
->brdnr
);
4562 set_bit(ASYI_TXBUSY
, &portp
->istate
);
4563 spin_unlock_irqrestore(&brd_lock
, flags
);
4566 /*****************************************************************************/
4569 * Disable all interrupts from this port.
4572 static void stl_sc26198disableintrs(stlport_t
*portp
)
4574 unsigned long flags
;
4577 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp
);
4580 spin_lock_irqsave(&brd_lock
, flags
);
4581 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4583 stl_sc26198setreg(portp
, IMR
, 0);
4584 BRDDISABLE(portp
->brdnr
);
4585 spin_unlock_irqrestore(&brd_lock
, flags
);
4588 /*****************************************************************************/
4590 static void stl_sc26198sendbreak(stlport_t
*portp
, int len
)
4592 unsigned long flags
;
4595 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
4598 spin_lock_irqsave(&brd_lock
, flags
);
4599 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4601 stl_sc26198setreg(portp
, SCCR
, CR_TXSTARTBREAK
);
4602 portp
->stats
.txbreaks
++;
4604 stl_sc26198setreg(portp
, SCCR
, CR_TXSTOPBREAK
);
4606 BRDDISABLE(portp
->brdnr
);
4607 spin_unlock_irqrestore(&brd_lock
, flags
);
4610 /*****************************************************************************/
4613 * Take flow control actions...
4616 static void stl_sc26198flowctrl(stlport_t
*portp
, int state
)
4618 struct tty_struct
*tty
;
4619 unsigned long flags
;
4623 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
4626 if (portp
== (stlport_t
*) NULL
)
4629 if (tty
== (struct tty_struct
*) NULL
)
4632 spin_lock_irqsave(&brd_lock
, flags
);
4633 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4636 if (tty
->termios
->c_iflag
& IXOFF
) {
4637 mr0
= stl_sc26198getreg(portp
, MR0
);
4638 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4639 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4641 portp
->stats
.rxxon
++;
4642 stl_sc26198wait(portp
);
4643 stl_sc26198setreg(portp
, MR0
, mr0
);
4646 * Question: should we return RTS to what it was before? It may
4647 * have been set by an ioctl... Suppose not, since if you have
4648 * hardware flow control set then it is pretty silly to go and
4649 * set the RTS line by hand.
4651 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4652 stl_sc26198setreg(portp
, MR1
,
4653 (stl_sc26198getreg(portp
, MR1
) | MR1_AUTORTS
));
4654 stl_sc26198setreg(portp
, IOPIOR
,
4655 (stl_sc26198getreg(portp
, IOPIOR
) | IOPR_RTS
));
4656 portp
->stats
.rxrtson
++;
4659 if (tty
->termios
->c_iflag
& IXOFF
) {
4660 mr0
= stl_sc26198getreg(portp
, MR0
);
4661 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4662 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4664 portp
->stats
.rxxoff
++;
4665 stl_sc26198wait(portp
);
4666 stl_sc26198setreg(portp
, MR0
, mr0
);
4668 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4669 stl_sc26198setreg(portp
, MR1
,
4670 (stl_sc26198getreg(portp
, MR1
) & ~MR1_AUTORTS
));
4671 stl_sc26198setreg(portp
, IOPIOR
,
4672 (stl_sc26198getreg(portp
, IOPIOR
) & ~IOPR_RTS
));
4673 portp
->stats
.rxrtsoff
++;
4677 BRDDISABLE(portp
->brdnr
);
4678 spin_unlock_irqrestore(&brd_lock
, flags
);
4681 /*****************************************************************************/
4684 * Send a flow control character.
4687 static void stl_sc26198sendflow(stlport_t
*portp
, int state
)
4689 struct tty_struct
*tty
;
4690 unsigned long flags
;
4694 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
4697 if (portp
== (stlport_t
*) NULL
)
4700 if (tty
== (struct tty_struct
*) NULL
)
4703 spin_lock_irqsave(&brd_lock
, flags
);
4704 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4706 mr0
= stl_sc26198getreg(portp
, MR0
);
4707 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4708 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4710 portp
->stats
.rxxon
++;
4711 stl_sc26198wait(portp
);
4712 stl_sc26198setreg(portp
, MR0
, mr0
);
4714 mr0
= stl_sc26198getreg(portp
, MR0
);
4715 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4716 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4718 portp
->stats
.rxxoff
++;
4719 stl_sc26198wait(portp
);
4720 stl_sc26198setreg(portp
, MR0
, mr0
);
4722 BRDDISABLE(portp
->brdnr
);
4723 spin_unlock_irqrestore(&brd_lock
, flags
);
4726 /*****************************************************************************/
4728 static void stl_sc26198flush(stlport_t
*portp
)
4730 unsigned long flags
;
4733 printk("stl_sc26198flush(portp=%x)\n", (int) portp
);
4736 if (portp
== (stlport_t
*) NULL
)
4739 spin_lock_irqsave(&brd_lock
, flags
);
4740 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4741 stl_sc26198setreg(portp
, SCCR
, CR_TXRESET
);
4742 stl_sc26198setreg(portp
, SCCR
, portp
->crenable
);
4743 BRDDISABLE(portp
->brdnr
);
4744 portp
->tx
.tail
= portp
->tx
.head
;
4745 spin_unlock_irqrestore(&brd_lock
, flags
);
4748 /*****************************************************************************/
4751 * Return the current state of data flow on this port. This is only
4752 * really interresting when determining if data has fully completed
4753 * transmission or not... The sc26198 interrupt scheme cannot
4754 * determine when all data has actually drained, so we need to
4755 * check the port statusy register to be sure.
4758 static int stl_sc26198datastate(stlport_t
*portp
)
4760 unsigned long flags
;
4764 printk("stl_sc26198datastate(portp=%x)\n", (int) portp
);
4767 if (portp
== (stlport_t
*) NULL
)
4769 if (test_bit(ASYI_TXBUSY
, &portp
->istate
))
4772 spin_lock_irqsave(&brd_lock
, flags
);
4773 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4774 sr
= stl_sc26198getreg(portp
, SR
);
4775 BRDDISABLE(portp
->brdnr
);
4776 spin_unlock_irqrestore(&brd_lock
, flags
);
4778 return (sr
& SR_TXEMPTY
) ? 0 : 1;
4781 /*****************************************************************************/
4784 * Delay for a small amount of time, to give the sc26198 a chance
4785 * to process a command...
4788 static void stl_sc26198wait(stlport_t
*portp
)
4793 printk("stl_sc26198wait(portp=%x)\n", (int) portp
);
4796 if (portp
== (stlport_t
*) NULL
)
4799 for (i
= 0; (i
< 20); i
++)
4800 stl_sc26198getglobreg(portp
, TSTR
);
4803 /*****************************************************************************/
4806 * If we are TX flow controlled and in IXANY mode then we may
4807 * need to unflow control here. We gotta do this because of the
4808 * automatic flow control modes of the sc26198.
4811 static inline void stl_sc26198txunflow(stlport_t
*portp
, struct tty_struct
*tty
)
4815 mr0
= stl_sc26198getreg(portp
, MR0
);
4816 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4817 stl_sc26198setreg(portp
, SCCR
, CR_HOSTXON
);
4818 stl_sc26198wait(portp
);
4819 stl_sc26198setreg(portp
, MR0
, mr0
);
4820 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
4823 /*****************************************************************************/
4826 * Interrupt service routine for sc26198 panels.
4829 static void stl_sc26198intr(stlpanel_t
*panelp
, unsigned int iobase
)
4834 spin_lock(&brd_lock
);
4837 * Work around bug in sc26198 chip... Cannot have A6 address
4838 * line of UART high, else iack will be returned as 0.
4840 outb(0, (iobase
+ 1));
4842 iack
= inb(iobase
+ XP_IACK
);
4843 portp
= panelp
->ports
[(iack
& IVR_CHANMASK
) + ((iobase
& 0x4) << 1)];
4845 if (iack
& IVR_RXDATA
)
4846 stl_sc26198rxisr(portp
, iack
);
4847 else if (iack
& IVR_TXDATA
)
4848 stl_sc26198txisr(portp
);
4850 stl_sc26198otherisr(portp
, iack
);
4852 spin_unlock(&brd_lock
);
4855 /*****************************************************************************/
4858 * Transmit interrupt handler. This has gotta be fast! Handling TX
4859 * chars is pretty simple, stuff as many as possible from the TX buffer
4860 * into the sc26198 FIFO.
4861 * In practice it is possible that interrupts are enabled but that the
4862 * port has been hung up. Need to handle not having any TX buffer here,
4863 * this is done by using the side effect that head and tail will also
4864 * be NULL if the buffer has been freed.
4867 static void stl_sc26198txisr(stlport_t
*portp
)
4869 unsigned int ioaddr
;
4875 printk("stl_sc26198txisr(portp=%x)\n", (int) portp
);
4878 ioaddr
= portp
->ioaddr
;
4879 head
= portp
->tx
.head
;
4880 tail
= portp
->tx
.tail
;
4881 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
4882 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
4883 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
4884 set_bit(ASYI_TXLOW
, &portp
->istate
);
4885 schedule_work(&portp
->tqueue
);
4889 outb((MR0
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
4890 mr0
= inb(ioaddr
+ XP_DATA
);
4891 if ((mr0
& MR0_TXMASK
) == MR0_TXEMPTY
) {
4892 portp
->imr
&= ~IR_TXRDY
;
4893 outb((IMR
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
4894 outb(portp
->imr
, (ioaddr
+ XP_DATA
));
4895 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
4897 mr0
|= ((mr0
& ~MR0_TXMASK
) | MR0_TXEMPTY
);
4898 outb(mr0
, (ioaddr
+ XP_DATA
));
4901 len
= MIN(len
, SC26198_TXFIFOSIZE
);
4902 portp
->stats
.txtotal
+= len
;
4903 stlen
= MIN(len
, ((portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
));
4904 outb(GTXFIFO
, (ioaddr
+ XP_ADDR
));
4905 outsb((ioaddr
+ XP_DATA
), tail
, stlen
);
4908 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
4909 tail
= portp
->tx
.buf
;
4911 outsb((ioaddr
+ XP_DATA
), tail
, len
);
4914 portp
->tx
.tail
= tail
;
4918 /*****************************************************************************/
4921 * Receive character interrupt handler. Determine if we have good chars
4922 * or bad chars and then process appropriately. Good chars are easy
4923 * just shove the lot into the RX buffer and set all status byte to 0.
4924 * If a bad RX char then process as required. This routine needs to be
4925 * fast! In practice it is possible that we get an interrupt on a port
4926 * that is closed. This can happen on hangups - since they completely
4927 * shutdown a port not in user context. Need to handle this case.
4930 static void stl_sc26198rxisr(stlport_t
*portp
, unsigned int iack
)
4932 struct tty_struct
*tty
;
4933 unsigned int len
, buflen
, ioaddr
;
4936 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
4940 ioaddr
= portp
->ioaddr
;
4941 outb(GIBCR
, (ioaddr
+ XP_ADDR
));
4942 len
= inb(ioaddr
+ XP_DATA
) + 1;
4944 if ((iack
& IVR_TYPEMASK
) == IVR_RXDATA
) {
4945 if (tty
== NULL
|| (buflen
= tty_buffer_request_room(tty
, len
)) == 0) {
4946 len
= MIN(len
, sizeof(stl_unwanted
));
4947 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
4948 insb((ioaddr
+ XP_DATA
), &stl_unwanted
[0], len
);
4949 portp
->stats
.rxlost
+= len
;
4950 portp
->stats
.rxtotal
+= len
;
4952 len
= MIN(len
, buflen
);
4955 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
4956 tty_prepare_flip_string(tty
, &ptr
, len
);
4957 insb((ioaddr
+ XP_DATA
), ptr
, len
);
4958 tty_schedule_flip(tty
);
4959 portp
->stats
.rxtotal
+= len
;
4963 stl_sc26198rxbadchars(portp
);
4967 * If we are TX flow controlled and in IXANY mode then we may need
4968 * to unflow control here. We gotta do this because of the automatic
4969 * flow control modes of the sc26198.
4971 if (test_bit(ASYI_TXFLOWED
, &portp
->istate
)) {
4972 if ((tty
!= (struct tty_struct
*) NULL
) &&
4973 (tty
->termios
!= (struct termios
*) NULL
) &&
4974 (tty
->termios
->c_iflag
& IXANY
)) {
4975 stl_sc26198txunflow(portp
, tty
);
4980 /*****************************************************************************/
4983 * Process an RX bad character.
4986 static inline void stl_sc26198rxbadch(stlport_t
*portp
, unsigned char status
, char ch
)
4988 struct tty_struct
*tty
;
4989 unsigned int ioaddr
;
4992 ioaddr
= portp
->ioaddr
;
4994 if (status
& SR_RXPARITY
)
4995 portp
->stats
.rxparity
++;
4996 if (status
& SR_RXFRAMING
)
4997 portp
->stats
.rxframing
++;
4998 if (status
& SR_RXOVERRUN
)
4999 portp
->stats
.rxoverrun
++;
5000 if (status
& SR_RXBREAK
)
5001 portp
->stats
.rxbreaks
++;
5003 if ((tty
!= (struct tty_struct
*) NULL
) &&
5004 ((portp
->rxignoremsk
& status
) == 0)) {
5005 if (portp
->rxmarkmsk
& status
) {
5006 if (status
& SR_RXBREAK
) {
5008 if (portp
->flags
& ASYNC_SAK
) {
5010 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
5012 } else if (status
& SR_RXPARITY
) {
5013 status
= TTY_PARITY
;
5014 } else if (status
& SR_RXFRAMING
) {
5016 } else if(status
& SR_RXOVERRUN
) {
5017 status
= TTY_OVERRUN
;
5025 tty_insert_flip_char(tty
, ch
, status
);
5026 tty_schedule_flip(tty
);
5029 portp
->stats
.rxtotal
++;
5033 /*****************************************************************************/
5036 * Process all characters in the RX FIFO of the UART. Check all char
5037 * status bytes as well, and process as required. We need to check
5038 * all bytes in the FIFO, in case some more enter the FIFO while we
5039 * are here. To get the exact character error type we need to switch
5040 * into CHAR error mode (that is why we need to make sure we empty
5044 static void stl_sc26198rxbadchars(stlport_t
*portp
)
5046 unsigned char status
, mr1
;
5050 * To get the precise error type for each character we must switch
5051 * back into CHAR error mode.
5053 mr1
= stl_sc26198getreg(portp
, MR1
);
5054 stl_sc26198setreg(portp
, MR1
, (mr1
& ~MR1_ERRBLOCK
));
5056 while ((status
= stl_sc26198getreg(portp
, SR
)) & SR_RXRDY
) {
5057 stl_sc26198setreg(portp
, SCCR
, CR_CLEARRXERR
);
5058 ch
= stl_sc26198getreg(portp
, RXFIFO
);
5059 stl_sc26198rxbadch(portp
, status
, ch
);
5063 * To get correct interrupt class we must switch back into BLOCK
5066 stl_sc26198setreg(portp
, MR1
, mr1
);
5069 /*****************************************************************************/
5072 * Other interrupt handler. This includes modem signals, flow
5073 * control actions, etc. Most stuff is left to off-level interrupt
5077 static void stl_sc26198otherisr(stlport_t
*portp
, unsigned int iack
)
5079 unsigned char cir
, ipr
, xisr
;
5082 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
5085 cir
= stl_sc26198getglobreg(portp
, CIR
);
5087 switch (cir
& CIR_SUBTYPEMASK
) {
5089 ipr
= stl_sc26198getreg(portp
, IPR
);
5090 if (ipr
& IPR_DCDCHANGE
) {
5091 set_bit(ASYI_DCDCHANGE
, &portp
->istate
);
5092 schedule_work(&portp
->tqueue
);
5093 portp
->stats
.modem
++;
5096 case CIR_SUBXONXOFF
:
5097 xisr
= stl_sc26198getreg(portp
, XISR
);
5098 if (xisr
& XISR_RXXONGOT
) {
5099 set_bit(ASYI_TXFLOWED
, &portp
->istate
);
5100 portp
->stats
.txxoff
++;
5102 if (xisr
& XISR_RXXOFFGOT
) {
5103 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
5104 portp
->stats
.txxon
++;
5108 stl_sc26198setreg(portp
, SCCR
, CR_BREAKRESET
);
5109 stl_sc26198rxbadchars(portp
);
5116 /*****************************************************************************/