1
/*****************************************************************************/
4
* stallion.c -- stallion multiport serial driver.
6
* Copyright (C) 1996-1999 Stallion Technologies
7
* Copyright (C) 1994-1996 Greg Ungerer.
9
* This code is loosely based on the Linux serial driver, written by
10
* Linus Torvalds, Theodore T'so and others.
12
* This program is free software; you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation; either version 2 of the License, or
15
* (at your option) any later version.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
/*****************************************************************************/
29
#include <linux/module.h>
30
#include <linux/sched.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/seq_file.h>
37
#include <linux/cd1400.h>
38
#include <linux/sc26198.h>
39
#include <linux/comstats.h>
40
#include <linux/stallion.h>
41
#include <linux/ioport.h>
42
#include <linux/init.h>
43
#include <linux/device.h>
44
#include <linux/delay.h>
45
#include <linux/ctype.h>
48
#include <asm/uaccess.h>
50
#include <linux/pci.h>
52
/*****************************************************************************/
55
* Define different board types. Use the standard Stallion "assigned"
56
* board numbers. Boards supported in this driver are abbreviated as
57
* EIO = EasyIO and ECH = EasyConnection 8/32.
63
#define BRD_ECH64PCI 27
64
#define BRD_EASYIOPCI 28
70
unsigned long memaddr;
75
static unsigned int stl_nrbrds;
77
/*****************************************************************************/
80
* Define some important driver characteristics. Device major numbers
81
* allocated as per Linux Device Registry.
83
#ifndef STL_SIOMEMMAJOR
84
#define STL_SIOMEMMAJOR 28
86
#ifndef STL_SERIALMAJOR
87
#define STL_SERIALMAJOR 24
89
#ifndef STL_CALLOUTMAJOR
90
#define STL_CALLOUTMAJOR 25
94
* Set the TX buffer size. Bigger is better, but we don't want
95
* to chew too much memory with buffers!
97
#define STL_TXBUFLOW 512
98
#define STL_TXBUFSIZE 4096
100
/*****************************************************************************/
103
* Define our local driver identity first. Set up stuff to deal with
104
* all the local structures required by a serial tty driver.
106
static char *stl_drvtitle = "Stallion Multiport Serial Driver";
107
static char *stl_drvname = "stallion";
108
static char *stl_drvversion = "5.6.0";
110
static struct tty_driver *stl_serial;
113
* Define a local default termios struct. All ports will be created
114
* with this termios initially. Basically all it defines is a raw port
115
* at 9600, 8 data bits, 1 stop bit.
117
static struct ktermios stl_deftermios = {
118
.c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
125
* Define global place to put buffer overflow characters.
127
static char stl_unwanted[SC26198_RXFIFOSIZE];
129
/*****************************************************************************/
131
static DEFINE_MUTEX(stl_brdslock);
132
static struct stlbrd *stl_brds[STL_MAXBRDS];
134
static const struct tty_port_operations stl_port_ops;
137
* Per board state flags. Used with the state field of the board struct.
138
* Not really much here!
140
#define BRD_FOUND 0x1
141
#define STL_PROBED 0x2
145
* Define the port structure istate flags. These set of flags are
146
* modified at interrupt time - so setting and reseting them needs
147
* to be atomic. Use the bit clear/setting routines for this.
149
#define ASYI_TXBUSY 1
151
#define ASYI_TXFLOWED 3
154
* Define an array of board names as printable strings. Handy for
155
* referencing boards when printing trace and stuff.
157
static char *stl_brdnames[] = {
189
/*****************************************************************************/
192
* Define some string labels for arguments passed from the module
193
* load line. These allow for easy board definitions, and easy
194
* modification of the io, memory and irq resoucres.
196
static unsigned int stl_nargs;
197
static char *board0[4];
198
static char *board1[4];
199
static char *board2[4];
200
static char *board3[4];
202
static char **stl_brdsp[] = {
210
* Define a set of common board names, and types. This is used to
211
* parse any module arguments.
218
{ "easyio", BRD_EASYIO },
219
{ "eio", BRD_EASYIO },
220
{ "20", BRD_EASYIO },
221
{ "ec8/32", BRD_ECH },
222
{ "ec8/32-at", BRD_ECH },
223
{ "ec8/32-isa", BRD_ECH },
225
{ "echat", BRD_ECH },
227
{ "ec8/32-mc", BRD_ECHMC },
228
{ "ec8/32-mca", BRD_ECHMC },
229
{ "echmc", BRD_ECHMC },
230
{ "echmca", BRD_ECHMC },
232
{ "ec8/32-pc", BRD_ECHPCI },
233
{ "ec8/32-pci", BRD_ECHPCI },
234
{ "26", BRD_ECHPCI },
235
{ "ec8/64-pc", BRD_ECH64PCI },
236
{ "ec8/64-pci", BRD_ECH64PCI },
237
{ "ech-pci", BRD_ECH64PCI },
238
{ "echpci", BRD_ECH64PCI },
239
{ "echpc", BRD_ECH64PCI },
240
{ "27", BRD_ECH64PCI },
241
{ "easyio-pc", BRD_EASYIOPCI },
242
{ "easyio-pci", BRD_EASYIOPCI },
243
{ "eio-pci", BRD_EASYIOPCI },
244
{ "eiopci", BRD_EASYIOPCI },
245
{ "28", BRD_EASYIOPCI },
249
* Define the module agruments.
252
module_param_array(board0, charp, &stl_nargs, 0);
253
MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
254
module_param_array(board1, charp, &stl_nargs, 0);
255
MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
256
module_param_array(board2, charp, &stl_nargs, 0);
257
MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
258
module_param_array(board3, charp, &stl_nargs, 0);
259
MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
261
/*****************************************************************************/
264
* Hardware ID bits for the EasyIO and ECH boards. These defines apply
265
* to the directly accessible io ports of these boards (not the uarts -
266
* they are in cd1400.h and sc26198.h).
268
#define EIO_8PORTRS 0x04
269
#define EIO_4PORTRS 0x05
270
#define EIO_8PORTDI 0x00
271
#define EIO_8PORTM 0x06
273
#define EIO_IDBITMASK 0x07
275
#define EIO_BRDMASK 0xf0
278
#define ID_BRD16 0x30
280
#define EIO_INTRPEND 0x08
281
#define EIO_INTEDGE 0x00
282
#define EIO_INTLEVEL 0x08
286
#define ECH_IDBITMASK 0xe0
287
#define ECH_BRDENABLE 0x08
288
#define ECH_BRDDISABLE 0x00
289
#define ECH_INTENABLE 0x01
290
#define ECH_INTDISABLE 0x00
291
#define ECH_INTLEVEL 0x02
292
#define ECH_INTEDGE 0x00
293
#define ECH_INTRPEND 0x01
294
#define ECH_BRDRESET 0x01
296
#define ECHMC_INTENABLE 0x01
297
#define ECHMC_BRDRESET 0x02
299
#define ECH_PNLSTATUS 2
300
#define ECH_PNL16PORT 0x20
301
#define ECH_PNLIDMASK 0x07
302
#define ECH_PNLXPID 0x40
303
#define ECH_PNLINTRPEND 0x80
305
#define ECH_ADDR2MASK 0x1e0
308
* Define the vector mapping bits for the programmable interrupt board
309
* hardware. These bits encode the interrupt for the board to use - it
310
* is software selectable (except the EIO-8M).
312
static unsigned char stl_vecmap[] = {
313
0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
314
0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
318
* Lock ordering is that you may not take stallion_lock holding
322
static spinlock_t brd_lock; /* Guard the board mapping */
323
static spinlock_t stallion_lock; /* Guard the tty driver */
326
* Set up enable and disable macros for the ECH boards. They require
327
* the secondary io address space to be activated and deactivated.
328
* This way all ECH boards can share their secondary io region.
329
* If this is an ECH-PCI board then also need to set the page pointer
330
* to point to the correct page.
332
#define BRDENABLE(brdnr,pagenr) \
333
if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
334
outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
335
stl_brds[(brdnr)]->ioctrl); \
336
else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
337
outb((pagenr), stl_brds[(brdnr)]->ioctrl);
339
#define BRDDISABLE(brdnr) \
340
if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
341
outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
342
stl_brds[(brdnr)]->ioctrl);
344
#define STL_CD1400MAXBAUD 230400
345
#define STL_SC26198MAXBAUD 460800
347
#define STL_BAUDBASE 115200
348
#define STL_CLOSEDELAY (5 * HZ / 10)
350
/*****************************************************************************/
353
* Define the Stallion PCI vendor and device IDs.
355
#ifndef PCI_VENDOR_ID_STALLION
356
#define PCI_VENDOR_ID_STALLION 0x124d
358
#ifndef PCI_DEVICE_ID_ECHPCI832
359
#define PCI_DEVICE_ID_ECHPCI832 0x0000
361
#ifndef PCI_DEVICE_ID_ECHPCI864
362
#define PCI_DEVICE_ID_ECHPCI864 0x0002
364
#ifndef PCI_DEVICE_ID_EIOPCI
365
#define PCI_DEVICE_ID_EIOPCI 0x0003
369
* Define structure to hold all Stallion PCI boards.
372
static struct pci_device_id stl_pcibrds[] = {
373
{ PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864),
374
.driver_data = BRD_ECH64PCI },
375
{ PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI),
376
.driver_data = BRD_EASYIOPCI },
377
{ PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832),
378
.driver_data = BRD_ECHPCI },
379
{ PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410),
380
.driver_data = BRD_ECHPCI },
383
MODULE_DEVICE_TABLE(pci, stl_pcibrds);
385
/*****************************************************************************/
388
* Define macros to extract a brd/port number from a minor number.
390
#define MINOR2BRD(min) (((min) & 0xc0) >> 6)
391
#define MINOR2PORT(min) ((min) & 0x3f)
394
* Define a baud rate table that converts termios baud rate selector
395
* into the actual baud rate value. All baud rate calculations are
396
* based on the actual baud rate required.
398
static unsigned int stl_baudrates[] = {
399
0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
400
9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
403
/*****************************************************************************/
406
* Declare all those functions in this driver!
409
static long stl_memioctl(struct file *fp, unsigned int cmd, unsigned long arg);
410
static int stl_brdinit(struct stlbrd *brdp);
411
static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp);
412
static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
415
* CD1400 uart specific handling functions.
417
static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
418
static int stl_cd1400getreg(struct stlport *portp, int regnr);
419
static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
420
static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
421
static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
422
static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp);
423
static int stl_cd1400getsignals(struct stlport *portp);
424
static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
425
static void stl_cd1400ccrwait(struct stlport *portp);
426
static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
427
static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
428
static void stl_cd1400disableintrs(struct stlport *portp);
429
static void stl_cd1400sendbreak(struct stlport *portp, int len);
430
static void stl_cd1400flowctrl(struct stlport *portp, int state);
431
static void stl_cd1400sendflow(struct stlport *portp, int state);
432
static void stl_cd1400flush(struct stlport *portp);
433
static int stl_cd1400datastate(struct stlport *portp);
434
static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
435
static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
436
static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
437
static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
438
static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
440
static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
443
* SC26198 uart specific handling functions.
445
static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
446
static int stl_sc26198getreg(struct stlport *portp, int regnr);
447
static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
448
static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
449
static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
450
static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
451
static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp);
452
static int stl_sc26198getsignals(struct stlport *portp);
453
static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
454
static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
455
static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
456
static void stl_sc26198disableintrs(struct stlport *portp);
457
static void stl_sc26198sendbreak(struct stlport *portp, int len);
458
static void stl_sc26198flowctrl(struct stlport *portp, int state);
459
static void stl_sc26198sendflow(struct stlport *portp, int state);
460
static void stl_sc26198flush(struct stlport *portp);
461
static int stl_sc26198datastate(struct stlport *portp);
462
static void stl_sc26198wait(struct stlport *portp);
463
static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
464
static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
465
static void stl_sc26198txisr(struct stlport *port);
466
static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
467
static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
468
static void stl_sc26198rxbadchars(struct stlport *portp);
469
static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
471
/*****************************************************************************/
474
* Generic UART support structure.
476
typedef struct uart {
477
int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
478
void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
479
void (*setport)(struct stlport *portp, struct ktermios *tiosp);
480
int (*getsignals)(struct stlport *portp);
481
void (*setsignals)(struct stlport *portp, int dtr, int rts);
482
void (*enablerxtx)(struct stlport *portp, int rx, int tx);
483
void (*startrxtx)(struct stlport *portp, int rx, int tx);
484
void (*disableintrs)(struct stlport *portp);
485
void (*sendbreak)(struct stlport *portp, int len);
486
void (*flowctrl)(struct stlport *portp, int state);
487
void (*sendflow)(struct stlport *portp, int state);
488
void (*flush)(struct stlport *portp);
489
int (*datastate)(struct stlport *portp);
490
void (*intr)(struct stlpanel *panelp, unsigned int iobase);
494
* Define some macros to make calling these functions nice and clean.
496
#define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
497
#define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
498
#define stl_setport (* ((uart_t *) portp->uartp)->setport)
499
#define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
500
#define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
501
#define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
502
#define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
503
#define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
504
#define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
505
#define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
506
#define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
507
#define stl_flush (* ((uart_t *) portp->uartp)->flush)
508
#define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
510
/*****************************************************************************/
513
* CD1400 UART specific data initialization.
515
static uart_t stl_cd1400uart = {
519
stl_cd1400getsignals,
520
stl_cd1400setsignals,
521
stl_cd1400enablerxtx,
523
stl_cd1400disableintrs,
533
* Define the offsets within the register bank of a cd1400 based panel.
534
* These io address offsets are common to the EasyIO board as well.
542
#define EREG_BANKSIZE 8
544
#define CD1400_CLK 25000000
545
#define CD1400_CLK8M 20000000
548
* Define the cd1400 baud rate clocks. These are used when calculating
549
* what clock and divisor to use for the required baud rate. Also
550
* define the maximum baud rate allowed, and the default base baud.
552
static int stl_cd1400clkdivs[] = {
553
CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
556
/*****************************************************************************/
559
* SC26198 UART specific data initization.
561
static uart_t stl_sc26198uart = {
562
stl_sc26198panelinit,
565
stl_sc26198getsignals,
566
stl_sc26198setsignals,
567
stl_sc26198enablerxtx,
568
stl_sc26198startrxtx,
569
stl_sc26198disableintrs,
570
stl_sc26198sendbreak,
574
stl_sc26198datastate,
579
* Define the offsets within the register bank of a sc26198 based panel.
587
#define XP_BANKSIZE 4
590
* Define the sc26198 baud rate table. Offsets within the table
591
* represent the actual baud rate selector of sc26198 registers.
593
static unsigned int sc26198_baudtable[] = {
594
50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
595
4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
596
230400, 460800, 921600
599
#define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
601
/*****************************************************************************/
604
* Define the driver info for a user level control device. Used mainly
605
* to get at port stats - only not using the port device itself.
607
static const struct file_operations stl_fsiomem = {
608
.owner = THIS_MODULE,
609
.unlocked_ioctl = stl_memioctl,
610
.llseek = noop_llseek,
613
static struct class *stallion_class;
615
static void stl_cd_change(struct stlport *portp)
617
unsigned int oldsigs = portp->sigs;
618
struct tty_struct *tty = tty_port_tty_get(&portp->port);
623
portp->sigs = stl_getsignals(portp);
625
if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
626
wake_up_interruptible(&portp->port.open_wait);
628
if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0))
629
if (portp->port.flags & ASYNC_CHECK_CD)
635
* Check for any arguments passed in on the module load command line.
638
/*****************************************************************************/
641
* Parse the supplied argument string, into the board conf struct.
644
static int __init stl_parsebrd(struct stlconf *confp, char **argp)
649
pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
651
if ((argp[0] == NULL) || (*argp[0] == 0))
654
for (sp = argp[0], i = 0; (*sp != 0) && (i < 25); sp++, i++)
657
for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++)
658
if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
661
if (i == ARRAY_SIZE(stl_brdstr)) {
662
printk("STALLION: unknown board name, %s?\n", argp[0]);
666
confp->brdtype = stl_brdstr[i].type;
669
if ((argp[i] != NULL) && (*argp[i] != 0))
670
confp->ioaddr1 = simple_strtoul(argp[i], NULL, 0);
672
if (confp->brdtype == BRD_ECH) {
673
if ((argp[i] != NULL) && (*argp[i] != 0))
674
confp->ioaddr2 = simple_strtoul(argp[i], NULL, 0);
677
if ((argp[i] != NULL) && (*argp[i] != 0))
678
confp->irq = simple_strtoul(argp[i], NULL, 0);
682
/*****************************************************************************/
685
* Allocate a new board structure. Fill out the basic info in it.
688
static struct stlbrd *stl_allocbrd(void)
692
brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
694
printk("STALLION: failed to allocate memory (size=%Zd)\n",
695
sizeof(struct stlbrd));
699
brdp->magic = STL_BOARDMAGIC;
703
/*****************************************************************************/
705
static int stl_activate(struct tty_port *port, struct tty_struct *tty)
707
struct stlport *portp = container_of(port, struct stlport, port);
708
if (!portp->tx.buf) {
709
portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
712
portp->tx.head = portp->tx.buf;
713
portp->tx.tail = portp->tx.buf;
715
stl_setport(portp, tty->termios);
716
portp->sigs = stl_getsignals(portp);
717
stl_setsignals(portp, 1, 1);
718
stl_enablerxtx(portp, 1, 1);
719
stl_startrxtx(portp, 1, 0);
723
static int stl_open(struct tty_struct *tty, struct file *filp)
725
struct stlport *portp;
727
unsigned int minordev, brdnr, panelnr;
730
pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
732
minordev = tty->index;
733
brdnr = MINOR2BRD(minordev);
734
if (brdnr >= stl_nrbrds)
736
brdp = stl_brds[brdnr];
740
minordev = MINOR2PORT(minordev);
741
for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) {
742
if (brdp->panels[panelnr] == NULL)
744
if (minordev < brdp->panels[panelnr]->nrports) {
748
minordev -= brdp->panels[panelnr]->nrports;
753
portp = brdp->panels[panelnr]->ports[portnr];
757
tty->driver_data = portp;
758
return tty_port_open(&portp->port, tty, filp);
762
/*****************************************************************************/
764
static int stl_carrier_raised(struct tty_port *port)
766
struct stlport *portp = container_of(port, struct stlport, port);
767
return (portp->sigs & TIOCM_CD) ? 1 : 0;
770
static void stl_dtr_rts(struct tty_port *port, int on)
772
struct stlport *portp = container_of(port, struct stlport, port);
773
/* Takes brd_lock internally */
774
stl_setsignals(portp, on, on);
777
/*****************************************************************************/
779
static void stl_flushbuffer(struct tty_struct *tty)
781
struct stlport *portp;
783
pr_debug("stl_flushbuffer(tty=%p)\n", tty);
785
portp = tty->driver_data;
793
/*****************************************************************************/
795
static void stl_waituntilsent(struct tty_struct *tty, int timeout)
797
struct stlport *portp;
800
pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
802
portp = tty->driver_data;
808
tend = jiffies + timeout;
810
while (stl_datastate(portp)) {
811
if (signal_pending(current))
813
msleep_interruptible(20);
814
if (time_after_eq(jiffies, tend))
819
/*****************************************************************************/
821
static void stl_shutdown(struct tty_port *port)
823
struct stlport *portp = container_of(port, struct stlport, port);
824
stl_disableintrs(portp);
825
stl_enablerxtx(portp, 0, 0);
828
if (portp->tx.buf != NULL) {
829
kfree(portp->tx.buf);
830
portp->tx.buf = NULL;
831
portp->tx.head = NULL;
832
portp->tx.tail = NULL;
836
static void stl_close(struct tty_struct *tty, struct file *filp)
838
struct stlport*portp;
839
pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
841
portp = tty->driver_data;
844
tty_port_close(&portp->port, tty, filp);
847
/*****************************************************************************/
850
* Write routine. Take data and stuff it in to the TX ring queue.
851
* If transmit interrupts are not running then start them.
854
static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
856
struct stlport *portp;
857
unsigned int len, stlen;
858
unsigned char *chbuf;
861
pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
863
portp = tty->driver_data;
866
if (portp->tx.buf == NULL)
870
* If copying direct from user space we must cater for page faults,
871
* causing us to "sleep" here for a while. To handle this copy in all
872
* the data we need now, into a local buffer. Then when we got it all
873
* copy it into the TX buffer.
875
chbuf = (unsigned char *) buf;
877
head = portp->tx.head;
878
tail = portp->tx.tail;
880
len = STL_TXBUFSIZE - (head - tail) - 1;
881
stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
883
len = tail - head - 1;
887
len = min(len, (unsigned int)count);
890
stlen = min(len, stlen);
891
memcpy(head, chbuf, stlen);
896
if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
897
head = portp->tx.buf;
901
portp->tx.head = head;
903
clear_bit(ASYI_TXLOW, &portp->istate);
904
stl_startrxtx(portp, -1, 1);
909
/*****************************************************************************/
911
static int stl_putchar(struct tty_struct *tty, unsigned char ch)
913
struct stlport *portp;
917
pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
919
portp = tty->driver_data;
922
if (portp->tx.buf == NULL)
925
head = portp->tx.head;
926
tail = portp->tx.tail;
928
len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
933
if (head >= (portp->tx.buf + STL_TXBUFSIZE))
934
head = portp->tx.buf;
936
portp->tx.head = head;
940
/*****************************************************************************/
943
* If there are any characters in the buffer then make sure that TX
944
* interrupts are on and get'em out. Normally used after the putchar
945
* routine has been called.
948
static void stl_flushchars(struct tty_struct *tty)
950
struct stlport *portp;
952
pr_debug("stl_flushchars(tty=%p)\n", tty);
954
portp = tty->driver_data;
957
if (portp->tx.buf == NULL)
960
stl_startrxtx(portp, -1, 1);
963
/*****************************************************************************/
965
static int stl_writeroom(struct tty_struct *tty)
967
struct stlport *portp;
970
pr_debug("stl_writeroom(tty=%p)\n", tty);
972
portp = tty->driver_data;
975
if (portp->tx.buf == NULL)
978
head = portp->tx.head;
979
tail = portp->tx.tail;
980
return (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1);
983
/*****************************************************************************/
986
* Return number of chars in the TX buffer. Normally we would just
987
* calculate the number of chars in the buffer and return that, but if
988
* the buffer is empty and TX interrupts are still on then we return
989
* that the buffer still has 1 char in it. This way whoever called us
990
* will not think that ALL chars have drained - since the UART still
991
* must have some chars in it (we are busy after all).
994
static int stl_charsinbuffer(struct tty_struct *tty)
996
struct stlport *portp;
1000
pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1002
portp = tty->driver_data;
1005
if (portp->tx.buf == NULL)
1008
head = portp->tx.head;
1009
tail = portp->tx.tail;
1010
size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1011
if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1016
/*****************************************************************************/
1019
* Generate the serial struct info.
1022
static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1024
struct serial_struct sio;
1025
struct stlbrd *brdp;
1027
pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1029
memset(&sio, 0, sizeof(struct serial_struct));
1031
mutex_lock(&portp->port.mutex);
1032
sio.line = portp->portnr;
1033
sio.port = portp->ioaddr;
1034
sio.flags = portp->port.flags;
1035
sio.baud_base = portp->baud_base;
1036
sio.close_delay = portp->close_delay;
1037
sio.closing_wait = portp->closing_wait;
1038
sio.custom_divisor = portp->custom_divisor;
1040
if (portp->uartp == &stl_cd1400uart) {
1041
sio.type = PORT_CIRRUS;
1042
sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1044
sio.type = PORT_UNKNOWN;
1045
sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1048
brdp = stl_brds[portp->brdnr];
1050
sio.irq = brdp->irq;
1051
mutex_unlock(&portp->port.mutex);
1053
return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1056
/*****************************************************************************/
1059
* Set port according to the serial struct info.
1060
* At this point we do not do any auto-configure stuff, so we will
1061
* just quietly ignore any requests to change irq, etc.
1064
static int stl_setserial(struct tty_struct *tty, struct serial_struct __user *sp)
1066
struct stlport * portp = tty->driver_data;
1067
struct serial_struct sio;
1069
pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1071
if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1073
mutex_lock(&portp->port.mutex);
1074
if (!capable(CAP_SYS_ADMIN)) {
1075
if ((sio.baud_base != portp->baud_base) ||
1076
(sio.close_delay != portp->close_delay) ||
1077
((sio.flags & ~ASYNC_USR_MASK) !=
1078
(portp->port.flags & ~ASYNC_USR_MASK))) {
1079
mutex_unlock(&portp->port.mutex);
1084
portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) |
1085
(sio.flags & ASYNC_USR_MASK);
1086
portp->baud_base = sio.baud_base;
1087
portp->close_delay = sio.close_delay;
1088
portp->closing_wait = sio.closing_wait;
1089
portp->custom_divisor = sio.custom_divisor;
1090
mutex_unlock(&portp->port.mutex);
1091
stl_setport(portp, tty->termios);
1095
/*****************************************************************************/
1097
static int stl_tiocmget(struct tty_struct *tty)
1099
struct stlport *portp;
1101
portp = tty->driver_data;
1104
if (tty->flags & (1 << TTY_IO_ERROR))
1107
return stl_getsignals(portp);
1110
static int stl_tiocmset(struct tty_struct *tty,
1111
unsigned int set, unsigned int clear)
1113
struct stlport *portp;
1114
int rts = -1, dtr = -1;
1116
portp = tty->driver_data;
1119
if (tty->flags & (1 << TTY_IO_ERROR))
1122
if (set & TIOCM_RTS)
1124
if (set & TIOCM_DTR)
1126
if (clear & TIOCM_RTS)
1128
if (clear & TIOCM_DTR)
1131
stl_setsignals(portp, dtr, rts);
1135
static int stl_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
1137
struct stlport *portp;
1139
void __user *argp = (void __user *)arg;
1141
pr_debug("stl_ioctl(tty=%p,cmd=%x,arg=%lx)\n", tty, cmd, arg);
1143
portp = tty->driver_data;
1147
if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1148
(cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS))
1149
if (tty->flags & (1 << TTY_IO_ERROR))
1156
rc = stl_getserial(portp, argp);
1159
rc = stl_setserial(tty, argp);
1161
case COM_GETPORTSTATS:
1162
rc = stl_getportstats(tty, portp, argp);
1164
case COM_CLRPORTSTATS:
1165
rc = stl_clrportstats(portp, argp);
1171
case TIOCSERGSTRUCT:
1172
case TIOCSERGETMULTI:
1173
case TIOCSERSETMULTI:
1181
/*****************************************************************************/
1184
* Start the transmitter again. Just turn TX interrupts back on.
1187
static void stl_start(struct tty_struct *tty)
1189
struct stlport *portp;
1191
pr_debug("stl_start(tty=%p)\n", tty);
1193
portp = tty->driver_data;
1196
stl_startrxtx(portp, -1, 1);
1199
/*****************************************************************************/
1201
static void stl_settermios(struct tty_struct *tty, struct ktermios *old)
1203
struct stlport *portp;
1204
struct ktermios *tiosp;
1206
pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1208
portp = tty->driver_data;
1212
tiosp = tty->termios;
1213
if ((tiosp->c_cflag == old->c_cflag) &&
1214
(tiosp->c_iflag == old->c_iflag))
1217
stl_setport(portp, tiosp);
1218
stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1220
if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1221
tty->hw_stopped = 0;
1224
if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1225
wake_up_interruptible(&portp->port.open_wait);
1228
/*****************************************************************************/
1231
* Attempt to flow control who ever is sending us data. Based on termios
1232
* settings use software or/and hardware flow control.
1235
static void stl_throttle(struct tty_struct *tty)
1237
struct stlport *portp;
1239
pr_debug("stl_throttle(tty=%p)\n", tty);
1241
portp = tty->driver_data;
1244
stl_flowctrl(portp, 0);
1247
/*****************************************************************************/
1250
* Unflow control the device sending us data...
1253
static void stl_unthrottle(struct tty_struct *tty)
1255
struct stlport *portp;
1257
pr_debug("stl_unthrottle(tty=%p)\n", tty);
1259
portp = tty->driver_data;
1262
stl_flowctrl(portp, 1);
1265
/*****************************************************************************/
1268
* Stop the transmitter. Basically to do this we will just turn TX
1272
static void stl_stop(struct tty_struct *tty)
1274
struct stlport *portp;
1276
pr_debug("stl_stop(tty=%p)\n", tty);
1278
portp = tty->driver_data;
1281
stl_startrxtx(portp, -1, 0);
1284
/*****************************************************************************/
1287
* Hangup this port. This is pretty much like closing the port, only
1288
* a little more brutal. No waiting for data to drain. Shutdown the
1289
* port and maybe drop signals.
1292
static void stl_hangup(struct tty_struct *tty)
1294
struct stlport *portp = tty->driver_data;
1295
pr_debug("stl_hangup(tty=%p)\n", tty);
1299
tty_port_hangup(&portp->port);
1302
/*****************************************************************************/
1304
static int stl_breakctl(struct tty_struct *tty, int state)
1306
struct stlport *portp;
1308
pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1310
portp = tty->driver_data;
1314
stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1318
/*****************************************************************************/
1320
static void stl_sendxchar(struct tty_struct *tty, char ch)
1322
struct stlport *portp;
1324
pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1326
portp = tty->driver_data;
1330
if (ch == STOP_CHAR(tty))
1331
stl_sendflow(portp, 0);
1332
else if (ch == START_CHAR(tty))
1333
stl_sendflow(portp, 1);
1335
stl_putchar(tty, ch);
1338
static void stl_portinfo(struct seq_file *m, struct stlport *portp, int portnr)
1343
seq_printf(m, "%d: uart:%s tx:%d rx:%d",
1344
portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1345
(int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1347
if (portp->stats.rxframing)
1348
seq_printf(m, " fe:%d", (int) portp->stats.rxframing);
1349
if (portp->stats.rxparity)
1350
seq_printf(m, " pe:%d", (int) portp->stats.rxparity);
1351
if (portp->stats.rxbreaks)
1352
seq_printf(m, " brk:%d", (int) portp->stats.rxbreaks);
1353
if (portp->stats.rxoverrun)
1354
seq_printf(m, " oe:%d", (int) portp->stats.rxoverrun);
1356
sigs = stl_getsignals(portp);
1358
if (sigs & TIOCM_RTS) {
1359
seq_printf(m, "%c%s", sep, "RTS");
1362
if (sigs & TIOCM_CTS) {
1363
seq_printf(m, "%c%s", sep, "CTS");
1366
if (sigs & TIOCM_DTR) {
1367
seq_printf(m, "%c%s", sep, "DTR");
1370
if (sigs & TIOCM_CD) {
1371
seq_printf(m, "%c%s", sep, "DCD");
1374
if (sigs & TIOCM_DSR) {
1375
seq_printf(m, "%c%s", sep, "DSR");
1381
/*****************************************************************************/
1384
* Port info, read from the /proc file system.
1387
static int stl_proc_show(struct seq_file *m, void *v)
1389
struct stlbrd *brdp;
1390
struct stlpanel *panelp;
1391
struct stlport *portp;
1392
unsigned int brdnr, panelnr, portnr;
1397
seq_printf(m, "%s: version %s\n", stl_drvtitle, stl_drvversion);
1400
* We scan through for each board, panel and port. The offset is
1401
* calculated on the fly, and irrelevant ports are skipped.
1403
for (brdnr = 0; brdnr < stl_nrbrds; brdnr++) {
1404
brdp = stl_brds[brdnr];
1407
if (brdp->state == 0)
1410
totalport = brdnr * STL_MAXPORTS;
1411
for (panelnr = 0; panelnr < brdp->nrpanels; panelnr++) {
1412
panelp = brdp->panels[panelnr];
1416
for (portnr = 0; portnr < panelp->nrports; portnr++,
1418
portp = panelp->ports[portnr];
1421
stl_portinfo(m, portp, totalport);
1428
static int stl_proc_open(struct inode *inode, struct file *file)
1430
return single_open(file, stl_proc_show, NULL);
1433
static const struct file_operations stl_proc_fops = {
1434
.owner = THIS_MODULE,
1435
.open = stl_proc_open,
1437
.llseek = seq_lseek,
1438
.release = single_release,
1441
/*****************************************************************************/
1444
* All board interrupts are vectored through here first. This code then
1445
* calls off to the approrpriate board interrupt handlers.
1448
static irqreturn_t stl_intr(int irq, void *dev_id)
1450
struct stlbrd *brdp = dev_id;
1452
pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, brdp->irq);
1454
return IRQ_RETVAL((* brdp->isr)(brdp));
1457
/*****************************************************************************/
1460
* Interrupt service routine for EasyIO board types.
1463
static int stl_eiointr(struct stlbrd *brdp)
1465
struct stlpanel *panelp;
1466
unsigned int iobase;
1469
spin_lock(&brd_lock);
1470
panelp = brdp->panels[0];
1471
iobase = panelp->iobase;
1472
while (inb(brdp->iostatus) & EIO_INTRPEND) {
1474
(* panelp->isr)(panelp, iobase);
1476
spin_unlock(&brd_lock);
1480
/*****************************************************************************/
1483
* Interrupt service routine for ECH-AT board types.
1486
static int stl_echatintr(struct stlbrd *brdp)
1488
struct stlpanel *panelp;
1489
unsigned int ioaddr, bnknr;
1492
outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1494
while (inb(brdp->iostatus) & ECH_INTRPEND) {
1496
for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1497
ioaddr = brdp->bnkstataddr[bnknr];
1498
if (inb(ioaddr) & ECH_PNLINTRPEND) {
1499
panelp = brdp->bnk2panel[bnknr];
1500
(* panelp->isr)(panelp, (ioaddr & 0xfffc));
1505
outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1510
/*****************************************************************************/
1513
* Interrupt service routine for ECH-MCA board types.
1516
static int stl_echmcaintr(struct stlbrd *brdp)
1518
struct stlpanel *panelp;
1519
unsigned int ioaddr, bnknr;
1522
while (inb(brdp->iostatus) & ECH_INTRPEND) {
1524
for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1525
ioaddr = brdp->bnkstataddr[bnknr];
1526
if (inb(ioaddr) & ECH_PNLINTRPEND) {
1527
panelp = brdp->bnk2panel[bnknr];
1528
(* panelp->isr)(panelp, (ioaddr & 0xfffc));
1535
/*****************************************************************************/
1538
* Interrupt service routine for ECH-PCI board types.
1541
static int stl_echpciintr(struct stlbrd *brdp)
1543
struct stlpanel *panelp;
1544
unsigned int ioaddr, bnknr, recheck;
1549
for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1550
outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
1551
ioaddr = brdp->bnkstataddr[bnknr];
1552
if (inb(ioaddr) & ECH_PNLINTRPEND) {
1553
panelp = brdp->bnk2panel[bnknr];
1554
(* panelp->isr)(panelp, (ioaddr & 0xfffc));
1565
/*****************************************************************************/
1568
* Interrupt service routine for ECH-8/64-PCI board types.
1571
static int stl_echpci64intr(struct stlbrd *brdp)
1573
struct stlpanel *panelp;
1574
unsigned int ioaddr, bnknr;
1577
while (inb(brdp->ioctrl) & 0x1) {
1579
for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1580
ioaddr = brdp->bnkstataddr[bnknr];
1581
if (inb(ioaddr) & ECH_PNLINTRPEND) {
1582
panelp = brdp->bnk2panel[bnknr];
1583
(* panelp->isr)(panelp, (ioaddr & 0xfffc));
1591
/*****************************************************************************/
1594
* Initialize all the ports on a panel.
1597
static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
1599
struct stlport *portp;
1603
pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
1605
chipmask = stl_panelinit(brdp, panelp);
1608
* All UART's are initialized (if found!). Now go through and setup
1609
* each ports data structures.
1611
for (i = 0; i < panelp->nrports; i++) {
1612
portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
1614
printk("STALLION: failed to allocate memory "
1615
"(size=%Zd)\n", sizeof(struct stlport));
1618
tty_port_init(&portp->port);
1619
portp->port.ops = &stl_port_ops;
1620
portp->magic = STL_PORTMAGIC;
1622
portp->brdnr = panelp->brdnr;
1623
portp->panelnr = panelp->panelnr;
1624
portp->uartp = panelp->uartp;
1625
portp->clk = brdp->clk;
1626
portp->baud_base = STL_BAUDBASE;
1627
portp->close_delay = STL_CLOSEDELAY;
1628
portp->closing_wait = 30 * HZ;
1629
init_waitqueue_head(&portp->port.open_wait);
1630
init_waitqueue_head(&portp->port.close_wait);
1631
portp->stats.brd = portp->brdnr;
1632
portp->stats.panel = portp->panelnr;
1633
portp->stats.port = portp->portnr;
1634
panelp->ports[i] = portp;
1635
stl_portinit(brdp, panelp, portp);
1641
static void stl_cleanup_panels(struct stlbrd *brdp)
1643
struct stlpanel *panelp;
1644
struct stlport *portp;
1646
struct tty_struct *tty;
1648
for (j = 0; j < STL_MAXPANELS; j++) {
1649
panelp = brdp->panels[j];
1652
for (k = 0; k < STL_PORTSPERPANEL; k++) {
1653
portp = panelp->ports[k];
1656
tty = tty_port_tty_get(&portp->port);
1661
kfree(portp->tx.buf);
1668
/*****************************************************************************/
1671
* Try to find and initialize an EasyIO board.
1674
static int __devinit stl_initeio(struct stlbrd *brdp)
1676
struct stlpanel *panelp;
1677
unsigned int status;
1681
pr_debug("stl_initeio(brdp=%p)\n", brdp);
1683
brdp->ioctrl = brdp->ioaddr1 + 1;
1684
brdp->iostatus = brdp->ioaddr1 + 2;
1686
status = inb(brdp->iostatus);
1687
if ((status & EIO_IDBITMASK) == EIO_MK3)
1691
* Handle board specific stuff now. The real difference is PCI
1694
if (brdp->brdtype == BRD_EASYIOPCI) {
1695
brdp->iosize1 = 0x80;
1696
brdp->iosize2 = 0x80;
1697
name = "serial(EIO-PCI)";
1698
outb(0x41, (brdp->ioaddr2 + 0x4c));
1701
name = "serial(EIO)";
1702
if ((brdp->irq < 0) || (brdp->irq > 15) ||
1703
(stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1704
printk("STALLION: invalid irq=%d for brd=%d\n",
1705
brdp->irq, brdp->brdnr);
1709
outb((stl_vecmap[brdp->irq] | EIO_0WS |
1710
((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
1715
if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
1716
printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
1717
"%x conflicts with another device\n", brdp->brdnr,
1722
if (brdp->iosize2 > 0)
1723
if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
1724
printk(KERN_WARNING "STALLION: Warning, board %d I/O "
1725
"address %x conflicts with another device\n",
1726
brdp->brdnr, brdp->ioaddr2);
1727
printk(KERN_WARNING "STALLION: Warning, also "
1728
"releasing board %d I/O address %x \n",
1729
brdp->brdnr, brdp->ioaddr1);
1734
* Everything looks OK, so let's go ahead and probe for the hardware.
1736
brdp->clk = CD1400_CLK;
1737
brdp->isr = stl_eiointr;
1740
switch (status & EIO_IDBITMASK) {
1742
brdp->clk = CD1400_CLK8M;
1752
switch (status & EIO_BRDMASK) {
1771
* We have verified that the board is actually present, so now we
1772
* can complete the setup.
1775
panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
1777
printk(KERN_WARNING "STALLION: failed to allocate memory "
1778
"(size=%Zd)\n", sizeof(struct stlpanel));
1783
panelp->magic = STL_PANELMAGIC;
1784
panelp->brdnr = brdp->brdnr;
1785
panelp->panelnr = 0;
1786
panelp->nrports = brdp->nrports;
1787
panelp->iobase = brdp->ioaddr1;
1788
panelp->hwid = status;
1789
if ((status & EIO_IDBITMASK) == EIO_MK3) {
1790
panelp->uartp = &stl_sc26198uart;
1791
panelp->isr = stl_sc26198intr;
1793
panelp->uartp = &stl_cd1400uart;
1794
panelp->isr = stl_cd1400eiointr;
1797
brdp->panels[0] = panelp;
1799
brdp->state |= BRD_FOUND;
1800
brdp->hwid = status;
1801
if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
1802
printk("STALLION: failed to register interrupt "
1803
"routine for %s irq=%d\n", name, brdp->irq);
1810
stl_cleanup_panels(brdp);
1812
if (brdp->iosize2 > 0)
1813
release_region(brdp->ioaddr2, brdp->iosize2);
1815
release_region(brdp->ioaddr1, brdp->iosize1);
1820
/*****************************************************************************/
1823
* Try to find an ECH board and initialize it. This code is capable of
1824
* dealing with all types of ECH board.
1827
static int __devinit stl_initech(struct stlbrd *brdp)
1829
struct stlpanel *panelp;
1830
unsigned int status, nxtid, ioaddr, conflict, panelnr, banknr, i;
1834
pr_debug("stl_initech(brdp=%p)\n", brdp);
1840
* Set up the initial board register contents for boards. This varies a
1841
* bit between the different board types. So we need to handle each
1842
* separately. Also do a check that the supplied IRQ is good.
1844
switch (brdp->brdtype) {
1847
brdp->isr = stl_echatintr;
1848
brdp->ioctrl = brdp->ioaddr1 + 1;
1849
brdp->iostatus = brdp->ioaddr1 + 1;
1850
status = inb(brdp->iostatus);
1851
if ((status & ECH_IDBITMASK) != ECH_ID) {
1855
if ((brdp->irq < 0) || (brdp->irq > 15) ||
1856
(stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1857
printk("STALLION: invalid irq=%d for brd=%d\n",
1858
brdp->irq, brdp->brdnr);
1862
status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
1863
status |= (stl_vecmap[brdp->irq] << 1);
1864
outb((status | ECH_BRDRESET), brdp->ioaddr1);
1865
brdp->ioctrlval = ECH_INTENABLE |
1866
((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
1867
for (i = 0; i < 10; i++)
1868
outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1871
name = "serial(EC8/32)";
1872
outb(status, brdp->ioaddr1);
1876
brdp->isr = stl_echmcaintr;
1877
brdp->ioctrl = brdp->ioaddr1 + 0x20;
1878
brdp->iostatus = brdp->ioctrl;
1879
status = inb(brdp->iostatus);
1880
if ((status & ECH_IDBITMASK) != ECH_ID) {
1884
if ((brdp->irq < 0) || (brdp->irq > 15) ||
1885
(stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1886
printk("STALLION: invalid irq=%d for brd=%d\n",
1887
brdp->irq, brdp->brdnr);
1891
outb(ECHMC_BRDRESET, brdp->ioctrl);
1892
outb(ECHMC_INTENABLE, brdp->ioctrl);
1894
name = "serial(EC8/32-MC)";
1898
brdp->isr = stl_echpciintr;
1899
brdp->ioctrl = brdp->ioaddr1 + 2;
1902
name = "serial(EC8/32-PCI)";
1906
brdp->isr = stl_echpci64intr;
1907
brdp->ioctrl = brdp->ioaddr2 + 0x40;
1908
outb(0x43, (brdp->ioaddr1 + 0x4c));
1909
brdp->iosize1 = 0x80;
1910
brdp->iosize2 = 0x80;
1911
name = "serial(EC8/64-PCI)";
1915
printk("STALLION: unknown board type=%d\n", brdp->brdtype);
1921
* Check boards for possible IO address conflicts and return fail status
1922
* if an IO conflict found.
1925
if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
1926
printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
1927
"%x conflicts with another device\n", brdp->brdnr,
1932
if (brdp->iosize2 > 0)
1933
if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
1934
printk(KERN_WARNING "STALLION: Warning, board %d I/O "
1935
"address %x conflicts with another device\n",
1936
brdp->brdnr, brdp->ioaddr2);
1937
printk(KERN_WARNING "STALLION: Warning, also "
1938
"releasing board %d I/O address %x \n",
1939
brdp->brdnr, brdp->ioaddr1);
1944
* Scan through the secondary io address space looking for panels.
1945
* As we find'em allocate and initialize panel structures for each.
1947
brdp->clk = CD1400_CLK;
1948
brdp->hwid = status;
1950
ioaddr = brdp->ioaddr2;
1955
for (i = 0; i < STL_MAXPANELS; i++) {
1956
if (brdp->brdtype == BRD_ECHPCI) {
1957
outb(nxtid, brdp->ioctrl);
1958
ioaddr = brdp->ioaddr2;
1960
status = inb(ioaddr + ECH_PNLSTATUS);
1961
if ((status & ECH_PNLIDMASK) != nxtid)
1963
panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
1965
printk("STALLION: failed to allocate memory "
1966
"(size=%Zd)\n", sizeof(struct stlpanel));
1970
panelp->magic = STL_PANELMAGIC;
1971
panelp->brdnr = brdp->brdnr;
1972
panelp->panelnr = panelnr;
1973
panelp->iobase = ioaddr;
1974
panelp->pagenr = nxtid;
1975
panelp->hwid = status;
1976
brdp->bnk2panel[banknr] = panelp;
1977
brdp->bnkpageaddr[banknr] = nxtid;
1978
brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
1980
if (status & ECH_PNLXPID) {
1981
panelp->uartp = &stl_sc26198uart;
1982
panelp->isr = stl_sc26198intr;
1983
if (status & ECH_PNL16PORT) {
1984
panelp->nrports = 16;
1985
brdp->bnk2panel[banknr] = panelp;
1986
brdp->bnkpageaddr[banknr] = nxtid;
1987
brdp->bnkstataddr[banknr++] = ioaddr + 4 +
1990
panelp->nrports = 8;
1992
panelp->uartp = &stl_cd1400uart;
1993
panelp->isr = stl_cd1400echintr;
1994
if (status & ECH_PNL16PORT) {
1995
panelp->nrports = 16;
1996
panelp->ackmask = 0x80;
1997
if (brdp->brdtype != BRD_ECHPCI)
1998
ioaddr += EREG_BANKSIZE;
1999
brdp->bnk2panel[banknr] = panelp;
2000
brdp->bnkpageaddr[banknr] = ++nxtid;
2001
brdp->bnkstataddr[banknr++] = ioaddr +
2004
panelp->nrports = 8;
2005
panelp->ackmask = 0xc0;
2010
ioaddr += EREG_BANKSIZE;
2011
brdp->nrports += panelp->nrports;
2012
brdp->panels[panelnr++] = panelp;
2013
if ((brdp->brdtype != BRD_ECHPCI) &&
2014
(ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) {
2020
brdp->nrpanels = panelnr;
2021
brdp->nrbnks = banknr;
2022
if (brdp->brdtype == BRD_ECH)
2023
outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2025
brdp->state |= BRD_FOUND;
2026
if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2027
printk("STALLION: failed to register interrupt "
2028
"routine for %s irq=%d\n", name, brdp->irq);
2035
stl_cleanup_panels(brdp);
2036
if (brdp->iosize2 > 0)
2037
release_region(brdp->ioaddr2, brdp->iosize2);
2039
release_region(brdp->ioaddr1, brdp->iosize1);
2044
/*****************************************************************************/
2047
* Initialize and configure the specified board.
2048
* Scan through all the boards in the configuration and see what we
2049
* can find. Handle EIO and the ECH boards a little differently here
2050
* since the initial search and setup is very different.
2053
static int __devinit stl_brdinit(struct stlbrd *brdp)
2057
pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2059
switch (brdp->brdtype) {
2062
retval = stl_initeio(brdp);
2070
retval = stl_initech(brdp);
2075
printk("STALLION: board=%d is unknown board type=%d\n",
2076
brdp->brdnr, brdp->brdtype);
2081
if ((brdp->state & BRD_FOUND) == 0) {
2082
printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2083
stl_brdnames[brdp->brdtype], brdp->brdnr,
2084
brdp->ioaddr1, brdp->irq);
2088
for (i = 0; i < STL_MAXPANELS; i++)
2089
if (brdp->panels[i] != NULL)
2090
stl_initports(brdp, brdp->panels[i]);
2092
printk("STALLION: %s found, board=%d io=%x irq=%d "
2093
"nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2094
brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2099
free_irq(brdp->irq, brdp);
2101
stl_cleanup_panels(brdp);
2103
release_region(brdp->ioaddr1, brdp->iosize1);
2104
if (brdp->iosize2 > 0)
2105
release_region(brdp->ioaddr2, brdp->iosize2);
2110
/*****************************************************************************/
2113
* Find the next available board number that is free.
2116
static int __devinit stl_getbrdnr(void)
2120
for (i = 0; i < STL_MAXBRDS; i++)
2121
if (stl_brds[i] == NULL) {
2122
if (i >= stl_nrbrds)
2130
/*****************************************************************************/
2132
* We have a Stallion board. Allocate a board structure and
2133
* initialize it. Read its IO and IRQ resources from PCI
2134
* configuration space.
2137
static int __devinit stl_pciprobe(struct pci_dev *pdev,
2138
const struct pci_device_id *ent)
2140
struct stlbrd *brdp;
2141
unsigned int i, brdtype = ent->driver_data;
2142
int brdnr, retval = -ENODEV;
2144
if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2147
retval = pci_enable_device(pdev);
2150
brdp = stl_allocbrd();
2155
mutex_lock(&stl_brdslock);
2156
brdnr = stl_getbrdnr();
2158
dev_err(&pdev->dev, "too many boards found, "
2159
"maximum supported %d\n", STL_MAXBRDS);
2160
mutex_unlock(&stl_brdslock);
2164
brdp->brdnr = (unsigned int)brdnr;
2165
stl_brds[brdp->brdnr] = brdp;
2166
mutex_unlock(&stl_brdslock);
2168
brdp->brdtype = brdtype;
2169
brdp->state |= STL_PROBED;
2172
* We have all resources from the board, so let's setup the actual
2173
* board structure now.
2177
brdp->ioaddr2 = pci_resource_start(pdev, 0);
2178
brdp->ioaddr1 = pci_resource_start(pdev, 1);
2181
brdp->ioaddr2 = pci_resource_start(pdev, 2);
2182
brdp->ioaddr1 = pci_resource_start(pdev, 1);
2185
brdp->ioaddr1 = pci_resource_start(pdev, 2);
2186
brdp->ioaddr2 = pci_resource_start(pdev, 1);
2189
dev_err(&pdev->dev, "unknown PCI board type=%u\n", brdtype);
2193
brdp->irq = pdev->irq;
2194
retval = stl_brdinit(brdp);
2198
pci_set_drvdata(pdev, brdp);
2200
for (i = 0; i < brdp->nrports; i++)
2201
tty_register_device(stl_serial,
2202
brdp->brdnr * STL_MAXPORTS + i, &pdev->dev);
2206
stl_brds[brdp->brdnr] = NULL;
2213
static void __devexit stl_pciremove(struct pci_dev *pdev)
2215
struct stlbrd *brdp = pci_get_drvdata(pdev);
2218
free_irq(brdp->irq, brdp);
2220
stl_cleanup_panels(brdp);
2222
release_region(brdp->ioaddr1, brdp->iosize1);
2223
if (brdp->iosize2 > 0)
2224
release_region(brdp->ioaddr2, brdp->iosize2);
2226
for (i = 0; i < brdp->nrports; i++)
2227
tty_unregister_device(stl_serial,
2228
brdp->brdnr * STL_MAXPORTS + i);
2230
stl_brds[brdp->brdnr] = NULL;
2234
static struct pci_driver stl_pcidriver = {
2236
.id_table = stl_pcibrds,
2237
.probe = stl_pciprobe,
2238
.remove = __devexit_p(stl_pciremove)
2241
/*****************************************************************************/
2244
* Return the board stats structure to user app.
2247
static int stl_getbrdstats(combrd_t __user *bp)
2249
combrd_t stl_brdstats;
2250
struct stlbrd *brdp;
2251
struct stlpanel *panelp;
2254
if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2256
if (stl_brdstats.brd >= STL_MAXBRDS)
2258
brdp = stl_brds[stl_brdstats.brd];
2262
memset(&stl_brdstats, 0, sizeof(combrd_t));
2263
stl_brdstats.brd = brdp->brdnr;
2264
stl_brdstats.type = brdp->brdtype;
2265
stl_brdstats.hwid = brdp->hwid;
2266
stl_brdstats.state = brdp->state;
2267
stl_brdstats.ioaddr = brdp->ioaddr1;
2268
stl_brdstats.ioaddr2 = brdp->ioaddr2;
2269
stl_brdstats.irq = brdp->irq;
2270
stl_brdstats.nrpanels = brdp->nrpanels;
2271
stl_brdstats.nrports = brdp->nrports;
2272
for (i = 0; i < brdp->nrpanels; i++) {
2273
panelp = brdp->panels[i];
2274
stl_brdstats.panels[i].panel = i;
2275
stl_brdstats.panels[i].hwid = panelp->hwid;
2276
stl_brdstats.panels[i].nrports = panelp->nrports;
2279
return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2282
/*****************************************************************************/
2285
* Resolve the referenced port number into a port struct pointer.
2288
static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2290
struct stlbrd *brdp;
2291
struct stlpanel *panelp;
2293
if (brdnr < 0 || brdnr >= STL_MAXBRDS)
2295
brdp = stl_brds[brdnr];
2298
if (panelnr < 0 || (unsigned int)panelnr >= brdp->nrpanels)
2300
panelp = brdp->panels[panelnr];
2303
if (portnr < 0 || (unsigned int)portnr >= panelp->nrports)
2305
return panelp->ports[portnr];
2308
/*****************************************************************************/
2311
* Return the port stats structure to user app. A NULL port struct
2312
* pointer passed in means that we need to find out from the app
2313
* what port to get stats for (used through board control device).
2316
static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp)
2318
comstats_t stl_comstats;
2319
unsigned char *head, *tail;
2320
unsigned long flags;
2323
if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2325
portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2331
mutex_lock(&portp->port.mutex);
2332
portp->stats.state = portp->istate;
2333
portp->stats.flags = portp->port.flags;
2334
portp->stats.hwid = portp->hwid;
2336
portp->stats.ttystate = 0;
2337
portp->stats.cflags = 0;
2338
portp->stats.iflags = 0;
2339
portp->stats.oflags = 0;
2340
portp->stats.lflags = 0;
2341
portp->stats.rxbuffered = 0;
2343
spin_lock_irqsave(&stallion_lock, flags);
2344
if (tty != NULL && portp->port.tty == tty) {
2345
portp->stats.ttystate = tty->flags;
2346
/* No longer available as a statistic */
2347
portp->stats.rxbuffered = 1; /*tty->flip.count; */
2348
if (tty->termios != NULL) {
2349
portp->stats.cflags = tty->termios->c_cflag;
2350
portp->stats.iflags = tty->termios->c_iflag;
2351
portp->stats.oflags = tty->termios->c_oflag;
2352
portp->stats.lflags = tty->termios->c_lflag;
2355
spin_unlock_irqrestore(&stallion_lock, flags);
2357
head = portp->tx.head;
2358
tail = portp->tx.tail;
2359
portp->stats.txbuffered = (head >= tail) ? (head - tail) :
2360
(STL_TXBUFSIZE - (tail - head));
2362
portp->stats.signals = (unsigned long) stl_getsignals(portp);
2363
mutex_unlock(&portp->port.mutex);
2365
return copy_to_user(cp, &portp->stats,
2366
sizeof(comstats_t)) ? -EFAULT : 0;
2369
/*****************************************************************************/
2372
* Clear the port stats structure. We also return it zeroed out...
2375
static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2377
comstats_t stl_comstats;
2380
if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2382
portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2388
mutex_lock(&portp->port.mutex);
2389
memset(&portp->stats, 0, sizeof(comstats_t));
2390
portp->stats.brd = portp->brdnr;
2391
portp->stats.panel = portp->panelnr;
2392
portp->stats.port = portp->portnr;
2393
mutex_unlock(&portp->port.mutex);
2394
return copy_to_user(cp, &portp->stats,
2395
sizeof(comstats_t)) ? -EFAULT : 0;
2398
/*****************************************************************************/
2401
* Return the entire driver ports structure to a user app.
2404
static int stl_getportstruct(struct stlport __user *arg)
2406
struct stlport stl_dummyport;
2407
struct stlport *portp;
2409
if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2411
portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2412
stl_dummyport.portnr);
2415
return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2418
/*****************************************************************************/
2421
* Return the entire driver board structure to a user app.
2424
static int stl_getbrdstruct(struct stlbrd __user *arg)
2426
struct stlbrd stl_dummybrd;
2427
struct stlbrd *brdp;
2429
if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2431
if (stl_dummybrd.brdnr >= STL_MAXBRDS)
2433
brdp = stl_brds[stl_dummybrd.brdnr];
2436
return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2439
/*****************************************************************************/
2442
* The "staliomem" device is also required to do some special operations
2443
* on the board and/or ports. In this driver it is mostly used for stats
2447
static long stl_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
2450
void __user *argp = (void __user *)arg;
2452
pr_debug("stl_memioctl(fp=%p,cmd=%x,arg=%lx)\n", fp, cmd,arg);
2454
brdnr = iminor(fp->f_dentry->d_inode);
2455
if (brdnr >= STL_MAXBRDS)
2460
case COM_GETPORTSTATS:
2461
rc = stl_getportstats(NULL, NULL, argp);
2463
case COM_CLRPORTSTATS:
2464
rc = stl_clrportstats(NULL, argp);
2466
case COM_GETBRDSTATS:
2467
rc = stl_getbrdstats(argp);
2470
rc = stl_getportstruct(argp);
2473
rc = stl_getbrdstruct(argp);
2482
static const struct tty_operations stl_ops = {
2486
.put_char = stl_putchar,
2487
.flush_chars = stl_flushchars,
2488
.write_room = stl_writeroom,
2489
.chars_in_buffer = stl_charsinbuffer,
2491
.set_termios = stl_settermios,
2492
.throttle = stl_throttle,
2493
.unthrottle = stl_unthrottle,
2496
.hangup = stl_hangup,
2497
.flush_buffer = stl_flushbuffer,
2498
.break_ctl = stl_breakctl,
2499
.wait_until_sent = stl_waituntilsent,
2500
.send_xchar = stl_sendxchar,
2501
.tiocmget = stl_tiocmget,
2502
.tiocmset = stl_tiocmset,
2503
.proc_fops = &stl_proc_fops,
2506
static const struct tty_port_operations stl_port_ops = {
2507
.carrier_raised = stl_carrier_raised,
2508
.dtr_rts = stl_dtr_rts,
2509
.activate = stl_activate,
2510
.shutdown = stl_shutdown,
2513
/*****************************************************************************/
2514
/* CD1400 HARDWARE FUNCTIONS */
2515
/*****************************************************************************/
2518
* These functions get/set/update the registers of the cd1400 UARTs.
2519
* Access to the cd1400 registers is via an address/data io port pair.
2520
* (Maybe should make this inline...)
2523
static int stl_cd1400getreg(struct stlport *portp, int regnr)
2525
outb((regnr + portp->uartaddr), portp->ioaddr);
2526
return inb(portp->ioaddr + EREG_DATA);
2529
static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
2531
outb(regnr + portp->uartaddr, portp->ioaddr);
2532
outb(value, portp->ioaddr + EREG_DATA);
2535
static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
2537
outb(regnr + portp->uartaddr, portp->ioaddr);
2538
if (inb(portp->ioaddr + EREG_DATA) != value) {
2539
outb(value, portp->ioaddr + EREG_DATA);
2545
/*****************************************************************************/
2548
* Inbitialize the UARTs in a panel. We don't care what sort of board
2549
* these ports are on - since the port io registers are almost
2550
* identical when dealing with ports.
2553
static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
2557
int nrchips, uartaddr, ioaddr;
2558
unsigned long flags;
2560
pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
2562
spin_lock_irqsave(&brd_lock, flags);
2563
BRDENABLE(panelp->brdnr, panelp->pagenr);
2566
* Check that each chip is present and started up OK.
2569
nrchips = panelp->nrports / CD1400_PORTS;
2570
for (i = 0; i < nrchips; i++) {
2571
if (brdp->brdtype == BRD_ECHPCI) {
2572
outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
2573
ioaddr = panelp->iobase;
2575
ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2576
uartaddr = (i & 0x01) ? 0x080 : 0;
2577
outb((GFRCR + uartaddr), ioaddr);
2578
outb(0, (ioaddr + EREG_DATA));
2579
outb((CCR + uartaddr), ioaddr);
2580
outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2581
outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2582
outb((GFRCR + uartaddr), ioaddr);
2583
for (j = 0; j < CCR_MAXWAIT; j++)
2584
if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
2587
if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
2588
printk("STALLION: cd1400 not responding, "
2589
"brd=%d panel=%d chip=%d\n",
2590
panelp->brdnr, panelp->panelnr, i);
2593
chipmask |= (0x1 << i);
2594
outb((PPR + uartaddr), ioaddr);
2595
outb(PPR_SCALAR, (ioaddr + EREG_DATA));
2598
BRDDISABLE(panelp->brdnr);
2599
spin_unlock_irqrestore(&brd_lock, flags);
2603
/*****************************************************************************/
2606
* Initialize hardware specific port registers.
2609
static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
2611
unsigned long flags;
2612
pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
2615
if ((brdp == NULL) || (panelp == NULL) ||
2619
spin_lock_irqsave(&brd_lock, flags);
2620
portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
2621
(portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
2622
portp->uartaddr = (portp->portnr & 0x04) << 5;
2623
portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
2625
BRDENABLE(portp->brdnr, portp->pagenr);
2626
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2627
stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
2628
portp->hwid = stl_cd1400getreg(portp, GFRCR);
2629
BRDDISABLE(portp->brdnr);
2630
spin_unlock_irqrestore(&brd_lock, flags);
2633
/*****************************************************************************/
2636
* Wait for the command register to be ready. We will poll this,
2637
* since it won't usually take too long to be ready.
2640
static void stl_cd1400ccrwait(struct stlport *portp)
2644
for (i = 0; i < CCR_MAXWAIT; i++)
2645
if (stl_cd1400getreg(portp, CCR) == 0)
2648
printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
2649
portp->portnr, portp->panelnr, portp->brdnr);
2652
/*****************************************************************************/
2655
* Set up the cd1400 registers for a port based on the termios port
2659
static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
2661
struct stlbrd *brdp;
2662
unsigned long flags;
2663
unsigned int clkdiv, baudrate;
2664
unsigned char cor1, cor2, cor3;
2665
unsigned char cor4, cor5, ccr;
2666
unsigned char srer, sreron, sreroff;
2667
unsigned char mcor1, mcor2, rtpr;
2668
unsigned char clk, div;
2684
brdp = stl_brds[portp->brdnr];
2689
* Set up the RX char ignore mask with those RX error types we
2690
* can ignore. We can get the cd1400 to help us out a little here,
2691
* it will ignore parity errors and breaks for us.
2693
portp->rxignoremsk = 0;
2694
if (tiosp->c_iflag & IGNPAR) {
2695
portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2696
cor1 |= COR1_PARIGNORE;
2698
if (tiosp->c_iflag & IGNBRK) {
2699
portp->rxignoremsk |= ST_BREAK;
2700
cor4 |= COR4_IGNBRK;
2703
portp->rxmarkmsk = ST_OVERRUN;
2704
if (tiosp->c_iflag & (INPCK | PARMRK))
2705
portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2706
if (tiosp->c_iflag & BRKINT)
2707
portp->rxmarkmsk |= ST_BREAK;
2710
* Go through the char size, parity and stop bits and set all the
2711
* option register appropriately.
2713
switch (tiosp->c_cflag & CSIZE) {
2728
if (tiosp->c_cflag & CSTOPB)
2733
if (tiosp->c_cflag & PARENB) {
2734
if (tiosp->c_cflag & PARODD)
2735
cor1 |= (COR1_PARENB | COR1_PARODD);
2737
cor1 |= (COR1_PARENB | COR1_PAREVEN);
2739
cor1 |= COR1_PARNONE;
2743
* Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
2744
* space for hardware flow control and the like. This should be set to
2745
* VMIN. Also here we will set the RX data timeout to 10ms - this should
2746
* really be based on VTIME.
2748
cor3 |= FIFO_RXTHRESHOLD;
2752
* Calculate the baud rate timers. For now we will just assume that
2753
* the input and output baud are the same. Could have used a baud
2754
* table here, but this way we can generate virtually any baud rate
2757
baudrate = tiosp->c_cflag & CBAUD;
2758
if (baudrate & CBAUDEX) {
2759
baudrate &= ~CBAUDEX;
2760
if ((baudrate < 1) || (baudrate > 4))
2761
tiosp->c_cflag &= ~CBAUDEX;
2765
baudrate = stl_baudrates[baudrate];
2766
if ((tiosp->c_cflag & CBAUD) == B38400) {
2767
if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2769
else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2771
else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2773
else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2775
else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2776
baudrate = (portp->baud_base / portp->custom_divisor);
2778
if (baudrate > STL_CD1400MAXBAUD)
2779
baudrate = STL_CD1400MAXBAUD;
2782
for (clk = 0; clk < CD1400_NUMCLKS; clk++) {
2783
clkdiv = (portp->clk / stl_cd1400clkdivs[clk]) / baudrate;
2787
div = (unsigned char) clkdiv;
2791
* Check what form of modem signaling is required and set it up.
2793
if ((tiosp->c_cflag & CLOCAL) == 0) {
2796
sreron |= SRER_MODEM;
2797
portp->port.flags |= ASYNC_CHECK_CD;
2799
portp->port.flags &= ~ASYNC_CHECK_CD;
2802
* Setup cd1400 enhanced modes if we can. In particular we want to
2803
* handle as much of the flow control as possible automatically. As
2804
* well as saving a few CPU cycles it will also greatly improve flow
2805
* control reliability.
2807
if (tiosp->c_iflag & IXON) {
2810
if (tiosp->c_iflag & IXANY)
2814
if (tiosp->c_cflag & CRTSCTS) {
2816
mcor1 |= FIFO_RTSTHRESHOLD;
2820
* All cd1400 register values calculated so go through and set
2824
pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
2825
portp->portnr, portp->panelnr, portp->brdnr);
2826
pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
2827
cor1, cor2, cor3, cor4, cor5);
2828
pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
2829
mcor1, mcor2, rtpr, sreron, sreroff);
2830
pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
2831
pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
2832
tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
2833
tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
2835
spin_lock_irqsave(&brd_lock, flags);
2836
BRDENABLE(portp->brdnr, portp->pagenr);
2837
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
2838
srer = stl_cd1400getreg(portp, SRER);
2839
stl_cd1400setreg(portp, SRER, 0);
2840
if (stl_cd1400updatereg(portp, COR1, cor1))
2842
if (stl_cd1400updatereg(portp, COR2, cor2))
2844
if (stl_cd1400updatereg(portp, COR3, cor3))
2847
stl_cd1400ccrwait(portp);
2848
stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
2850
stl_cd1400setreg(portp, COR4, cor4);
2851
stl_cd1400setreg(portp, COR5, cor5);
2852
stl_cd1400setreg(portp, MCOR1, mcor1);
2853
stl_cd1400setreg(portp, MCOR2, mcor2);
2855
stl_cd1400setreg(portp, TCOR, clk);
2856
stl_cd1400setreg(portp, TBPR, div);
2857
stl_cd1400setreg(portp, RCOR, clk);
2858
stl_cd1400setreg(portp, RBPR, div);
2860
stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
2861
stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
2862
stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
2863
stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
2864
stl_cd1400setreg(portp, RTPR, rtpr);
2865
mcor1 = stl_cd1400getreg(portp, MSVR1);
2866
if (mcor1 & MSVR1_DCD)
2867
portp->sigs |= TIOCM_CD;
2869
portp->sigs &= ~TIOCM_CD;
2870
stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
2871
BRDDISABLE(portp->brdnr);
2872
spin_unlock_irqrestore(&brd_lock, flags);
2875
/*****************************************************************************/
2878
* Set the state of the DTR and RTS signals.
2881
static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
2883
unsigned char msvr1, msvr2;
2884
unsigned long flags;
2886
pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
2896
spin_lock_irqsave(&brd_lock, flags);
2897
BRDENABLE(portp->brdnr, portp->pagenr);
2898
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2900
stl_cd1400setreg(portp, MSVR2, msvr2);
2902
stl_cd1400setreg(portp, MSVR1, msvr1);
2903
BRDDISABLE(portp->brdnr);
2904
spin_unlock_irqrestore(&brd_lock, flags);
2907
/*****************************************************************************/
2910
* Return the state of the signals.
2913
static int stl_cd1400getsignals(struct stlport *portp)
2915
unsigned char msvr1, msvr2;
2916
unsigned long flags;
2919
pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
2921
spin_lock_irqsave(&brd_lock, flags);
2922
BRDENABLE(portp->brdnr, portp->pagenr);
2923
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2924
msvr1 = stl_cd1400getreg(portp, MSVR1);
2925
msvr2 = stl_cd1400getreg(portp, MSVR2);
2926
BRDDISABLE(portp->brdnr);
2927
spin_unlock_irqrestore(&brd_lock, flags);
2930
sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
2931
sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
2932
sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
2933
sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
2935
sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
2936
sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
2943
/*****************************************************************************/
2946
* Enable/Disable the Transmitter and/or Receiver.
2949
static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
2952
unsigned long flags;
2954
pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
2959
ccr |= CCR_TXDISABLE;
2961
ccr |= CCR_TXENABLE;
2963
ccr |= CCR_RXDISABLE;
2965
ccr |= CCR_RXENABLE;
2967
spin_lock_irqsave(&brd_lock, flags);
2968
BRDENABLE(portp->brdnr, portp->pagenr);
2969
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2970
stl_cd1400ccrwait(portp);
2971
stl_cd1400setreg(portp, CCR, ccr);
2972
stl_cd1400ccrwait(portp);
2973
BRDDISABLE(portp->brdnr);
2974
spin_unlock_irqrestore(&brd_lock, flags);
2977
/*****************************************************************************/
2980
* Start/stop the Transmitter and/or Receiver.
2983
static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
2985
unsigned char sreron, sreroff;
2986
unsigned long flags;
2988
pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
2993
sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
2995
sreron |= SRER_TXDATA;
2997
sreron |= SRER_TXEMPTY;
2999
sreroff |= SRER_RXDATA;
3001
sreron |= SRER_RXDATA;
3003
spin_lock_irqsave(&brd_lock, flags);
3004
BRDENABLE(portp->brdnr, portp->pagenr);
3005
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3006
stl_cd1400setreg(portp, SRER,
3007
((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3008
BRDDISABLE(portp->brdnr);
3010
set_bit(ASYI_TXBUSY, &portp->istate);
3011
spin_unlock_irqrestore(&brd_lock, flags);
3014
/*****************************************************************************/
3017
* Disable all interrupts from this port.
3020
static void stl_cd1400disableintrs(struct stlport *portp)
3022
unsigned long flags;
3024
pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3026
spin_lock_irqsave(&brd_lock, flags);
3027
BRDENABLE(portp->brdnr, portp->pagenr);
3028
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3029
stl_cd1400setreg(portp, SRER, 0);
3030
BRDDISABLE(portp->brdnr);
3031
spin_unlock_irqrestore(&brd_lock, flags);
3034
/*****************************************************************************/
3036
static void stl_cd1400sendbreak(struct stlport *portp, int len)
3038
unsigned long flags;
3040
pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3042
spin_lock_irqsave(&brd_lock, flags);
3043
BRDENABLE(portp->brdnr, portp->pagenr);
3044
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3045
stl_cd1400setreg(portp, SRER,
3046
((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3048
BRDDISABLE(portp->brdnr);
3049
portp->brklen = len;
3051
portp->stats.txbreaks++;
3052
spin_unlock_irqrestore(&brd_lock, flags);
3055
/*****************************************************************************/
3058
* Take flow control actions...
3061
static void stl_cd1400flowctrl(struct stlport *portp, int state)
3063
struct tty_struct *tty;
3064
unsigned long flags;
3066
pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3070
tty = tty_port_tty_get(&portp->port);
3074
spin_lock_irqsave(&brd_lock, flags);
3075
BRDENABLE(portp->brdnr, portp->pagenr);
3076
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3079
if (tty->termios->c_iflag & IXOFF) {
3080
stl_cd1400ccrwait(portp);
3081
stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3082
portp->stats.rxxon++;
3083
stl_cd1400ccrwait(portp);
3086
* Question: should we return RTS to what it was before? It may
3087
* have been set by an ioctl... Suppose not, since if you have
3088
* hardware flow control set then it is pretty silly to go and
3089
* set the RTS line by hand.
3091
if (tty->termios->c_cflag & CRTSCTS) {
3092
stl_cd1400setreg(portp, MCOR1,
3093
(stl_cd1400getreg(portp, MCOR1) |
3094
FIFO_RTSTHRESHOLD));
3095
stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3096
portp->stats.rxrtson++;
3099
if (tty->termios->c_iflag & IXOFF) {
3100
stl_cd1400ccrwait(portp);
3101
stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3102
portp->stats.rxxoff++;
3103
stl_cd1400ccrwait(portp);
3105
if (tty->termios->c_cflag & CRTSCTS) {
3106
stl_cd1400setreg(portp, MCOR1,
3107
(stl_cd1400getreg(portp, MCOR1) & 0xf0));
3108
stl_cd1400setreg(portp, MSVR2, 0);
3109
portp->stats.rxrtsoff++;
3113
BRDDISABLE(portp->brdnr);
3114
spin_unlock_irqrestore(&brd_lock, flags);
3118
/*****************************************************************************/
3121
* Send a flow control character...
3124
static void stl_cd1400sendflow(struct stlport *portp, int state)
3126
struct tty_struct *tty;
3127
unsigned long flags;
3129
pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3133
tty = tty_port_tty_get(&portp->port);
3137
spin_lock_irqsave(&brd_lock, flags);
3138
BRDENABLE(portp->brdnr, portp->pagenr);
3139
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3141
stl_cd1400ccrwait(portp);
3142
stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3143
portp->stats.rxxon++;
3144
stl_cd1400ccrwait(portp);
3146
stl_cd1400ccrwait(portp);
3147
stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3148
portp->stats.rxxoff++;
3149
stl_cd1400ccrwait(portp);
3151
BRDDISABLE(portp->brdnr);
3152
spin_unlock_irqrestore(&brd_lock, flags);
3156
/*****************************************************************************/
3158
static void stl_cd1400flush(struct stlport *portp)
3160
unsigned long flags;
3162
pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3167
spin_lock_irqsave(&brd_lock, flags);
3168
BRDENABLE(portp->brdnr, portp->pagenr);
3169
stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3170
stl_cd1400ccrwait(portp);
3171
stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3172
stl_cd1400ccrwait(portp);
3173
portp->tx.tail = portp->tx.head;
3174
BRDDISABLE(portp->brdnr);
3175
spin_unlock_irqrestore(&brd_lock, flags);
3178
/*****************************************************************************/
3181
* Return the current state of data flow on this port. This is only
3182
* really interesting when determining if data has fully completed
3183
* transmission or not... This is easy for the cd1400, it accurately
3184
* maintains the busy port flag.
3187
static int stl_cd1400datastate(struct stlport *portp)
3189
pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3194
return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3197
/*****************************************************************************/
3200
* Interrupt service routine for cd1400 EasyIO boards.
3203
static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3205
unsigned char svrtype;
3207
pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3209
spin_lock(&brd_lock);
3211
svrtype = inb(iobase + EREG_DATA);
3212
if (panelp->nrports > 4) {
3213
outb((SVRR + 0x80), iobase);
3214
svrtype |= inb(iobase + EREG_DATA);
3217
if (svrtype & SVRR_RX)
3218
stl_cd1400rxisr(panelp, iobase);
3219
else if (svrtype & SVRR_TX)
3220
stl_cd1400txisr(panelp, iobase);
3221
else if (svrtype & SVRR_MDM)
3222
stl_cd1400mdmisr(panelp, iobase);
3224
spin_unlock(&brd_lock);
3227
/*****************************************************************************/
3230
* Interrupt service routine for cd1400 panels.
3233
static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3235
unsigned char svrtype;
3237
pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3240
svrtype = inb(iobase + EREG_DATA);
3241
outb((SVRR + 0x80), iobase);
3242
svrtype |= inb(iobase + EREG_DATA);
3243
if (svrtype & SVRR_RX)
3244
stl_cd1400rxisr(panelp, iobase);
3245
else if (svrtype & SVRR_TX)
3246
stl_cd1400txisr(panelp, iobase);
3247
else if (svrtype & SVRR_MDM)
3248
stl_cd1400mdmisr(panelp, iobase);
3252
/*****************************************************************************/
3255
* Unfortunately we need to handle breaks in the TX data stream, since
3256
* this is the only way to generate them on the cd1400.
3259
static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3261
if (portp->brklen == 1) {
3262
outb((COR2 + portp->uartaddr), ioaddr);
3263
outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3264
(ioaddr + EREG_DATA));
3265
outb((TDR + portp->uartaddr), ioaddr);
3266
outb(ETC_CMD, (ioaddr + EREG_DATA));
3267
outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3268
outb((SRER + portp->uartaddr), ioaddr);
3269
outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3270
(ioaddr + EREG_DATA));
3272
} else if (portp->brklen > 1) {
3273
outb((TDR + portp->uartaddr), ioaddr);
3274
outb(ETC_CMD, (ioaddr + EREG_DATA));
3275
outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3279
outb((COR2 + portp->uartaddr), ioaddr);
3280
outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3281
(ioaddr + EREG_DATA));
3287
/*****************************************************************************/
3290
* Transmit interrupt handler. This has gotta be fast! Handling TX
3291
* chars is pretty simple, stuff as many as possible from the TX buffer
3292
* into the cd1400 FIFO. Must also handle TX breaks here, since they
3293
* are embedded as commands in the data stream. Oh no, had to use a goto!
3294
* This could be optimized more, will do when I get time...
3295
* In practice it is possible that interrupts are enabled but that the
3296
* port has been hung up. Need to handle not having any TX buffer here,
3297
* this is done by using the side effect that head and tail will also
3298
* be NULL if the buffer has been freed.
3301
static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3303
struct stlport *portp;
3306
unsigned char ioack, srer;
3307
struct tty_struct *tty;
3309
pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3311
ioack = inb(ioaddr + EREG_TXACK);
3312
if (((ioack & panelp->ackmask) != 0) ||
3313
((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3314
printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3317
portp = panelp->ports[(ioack >> 3)];
3320
* Unfortunately we need to handle breaks in the data stream, since
3321
* this is the only way to generate them on the cd1400. Do it now if
3322
* a break is to be sent.
3324
if (portp->brklen != 0)
3325
if (stl_cd1400breakisr(portp, ioaddr))
3328
head = portp->tx.head;
3329
tail = portp->tx.tail;
3330
len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3331
if ((len == 0) || ((len < STL_TXBUFLOW) &&
3332
(test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3333
set_bit(ASYI_TXLOW, &portp->istate);
3334
tty = tty_port_tty_get(&portp->port);
3342
outb((SRER + portp->uartaddr), ioaddr);
3343
srer = inb(ioaddr + EREG_DATA);
3344
if (srer & SRER_TXDATA) {
3345
srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3347
srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3348
clear_bit(ASYI_TXBUSY, &portp->istate);
3350
outb(srer, (ioaddr + EREG_DATA));
3352
len = min(len, CD1400_TXFIFOSIZE);
3353
portp->stats.txtotal += len;
3354
stlen = min_t(unsigned int, len,
3355
(portp->tx.buf + STL_TXBUFSIZE) - tail);
3356
outb((TDR + portp->uartaddr), ioaddr);
3357
outsb((ioaddr + EREG_DATA), tail, stlen);
3360
if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3361
tail = portp->tx.buf;
3363
outsb((ioaddr + EREG_DATA), tail, len);
3366
portp->tx.tail = tail;
3370
outb((EOSRR + portp->uartaddr), ioaddr);
3371
outb(0, (ioaddr + EREG_DATA));
3374
/*****************************************************************************/
3377
* Receive character interrupt handler. Determine if we have good chars
3378
* or bad chars and then process appropriately. Good chars are easy
3379
* just shove the lot into the RX buffer and set all status byte to 0.
3380
* If a bad RX char then process as required. This routine needs to be
3381
* fast! In practice it is possible that we get an interrupt on a port
3382
* that is closed. This can happen on hangups - since they completely
3383
* shutdown a port not in user context. Need to handle this case.
3386
static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3388
struct stlport *portp;
3389
struct tty_struct *tty;
3390
unsigned int ioack, len, buflen;
3391
unsigned char status;
3394
pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3396
ioack = inb(ioaddr + EREG_RXACK);
3397
if ((ioack & panelp->ackmask) != 0) {
3398
printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3401
portp = panelp->ports[(ioack >> 3)];
3402
tty = tty_port_tty_get(&portp->port);
3404
if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3405
outb((RDCR + portp->uartaddr), ioaddr);
3406
len = inb(ioaddr + EREG_DATA);
3407
if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3408
len = min_t(unsigned int, len, sizeof(stl_unwanted));
3409
outb((RDSR + portp->uartaddr), ioaddr);
3410
insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3411
portp->stats.rxlost += len;
3412
portp->stats.rxtotal += len;
3414
len = min(len, buflen);
3417
outb((RDSR + portp->uartaddr), ioaddr);
3418
tty_prepare_flip_string(tty, &ptr, len);
3419
insb((ioaddr + EREG_DATA), ptr, len);
3420
tty_schedule_flip(tty);
3421
portp->stats.rxtotal += len;
3424
} else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3425
outb((RDSR + portp->uartaddr), ioaddr);
3426
status = inb(ioaddr + EREG_DATA);
3427
ch = inb(ioaddr + EREG_DATA);
3428
if (status & ST_PARITY)
3429
portp->stats.rxparity++;
3430
if (status & ST_FRAMING)
3431
portp->stats.rxframing++;
3432
if (status & ST_OVERRUN)
3433
portp->stats.rxoverrun++;
3434
if (status & ST_BREAK)
3435
portp->stats.rxbreaks++;
3436
if (status & ST_SCHARMASK) {
3437
if ((status & ST_SCHARMASK) == ST_SCHAR1)
3438
portp->stats.txxon++;
3439
if ((status & ST_SCHARMASK) == ST_SCHAR2)
3440
portp->stats.txxoff++;
3443
if (tty != NULL && (portp->rxignoremsk & status) == 0) {
3444
if (portp->rxmarkmsk & status) {
3445
if (status & ST_BREAK) {
3447
if (portp->port.flags & ASYNC_SAK) {
3449
BRDENABLE(portp->brdnr, portp->pagenr);
3451
} else if (status & ST_PARITY)
3452
status = TTY_PARITY;
3453
else if (status & ST_FRAMING)
3455
else if(status & ST_OVERRUN)
3456
status = TTY_OVERRUN;
3461
tty_insert_flip_char(tty, ch, status);
3462
tty_schedule_flip(tty);
3465
printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3472
outb((EOSRR + portp->uartaddr), ioaddr);
3473
outb(0, (ioaddr + EREG_DATA));
3476
/*****************************************************************************/
3479
* Modem interrupt handler. The is called when the modem signal line
3480
* (DCD) has changed state. Leave most of the work to the off-level
3481
* processing routine.
3484
static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
3486
struct stlport *portp;
3490
pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
3492
ioack = inb(ioaddr + EREG_MDACK);
3493
if (((ioack & panelp->ackmask) != 0) ||
3494
((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3495
printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3498
portp = panelp->ports[(ioack >> 3)];
3500
outb((MISR + portp->uartaddr), ioaddr);
3501
misr = inb(ioaddr + EREG_DATA);
3502
if (misr & MISR_DCD) {
3503
stl_cd_change(portp);
3504
portp->stats.modem++;
3507
outb((EOSRR + portp->uartaddr), ioaddr);
3508
outb(0, (ioaddr + EREG_DATA));
3511
/*****************************************************************************/
3512
/* SC26198 HARDWARE FUNCTIONS */
3513
/*****************************************************************************/
3516
* These functions get/set/update the registers of the sc26198 UARTs.
3517
* Access to the sc26198 registers is via an address/data io port pair.
3518
* (Maybe should make this inline...)
3521
static int stl_sc26198getreg(struct stlport *portp, int regnr)
3523
outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3524
return inb(portp->ioaddr + XP_DATA);
3527
static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
3529
outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3530
outb(value, (portp->ioaddr + XP_DATA));
3533
static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
3535
outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3536
if (inb(portp->ioaddr + XP_DATA) != value) {
3537
outb(value, (portp->ioaddr + XP_DATA));
3543
/*****************************************************************************/
3546
* Functions to get and set the sc26198 global registers.
3549
static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
3551
outb(regnr, (portp->ioaddr + XP_ADDR));
3552
return inb(portp->ioaddr + XP_DATA);
3556
static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
3558
outb(regnr, (portp->ioaddr + XP_ADDR));
3559
outb(value, (portp->ioaddr + XP_DATA));
3563
/*****************************************************************************/
3566
* Inbitialize the UARTs in a panel. We don't care what sort of board
3567
* these ports are on - since the port io registers are almost
3568
* identical when dealing with ports.
3571
static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3574
int nrchips, ioaddr;
3576
pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3578
BRDENABLE(panelp->brdnr, panelp->pagenr);
3581
* Check that each chip is present and started up OK.
3584
nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3585
if (brdp->brdtype == BRD_ECHPCI)
3586
outb(panelp->pagenr, brdp->ioctrl);
3588
for (i = 0; i < nrchips; i++) {
3589
ioaddr = panelp->iobase + (i * 4);
3590
outb(SCCR, (ioaddr + XP_ADDR));
3591
outb(CR_RESETALL, (ioaddr + XP_DATA));
3592
outb(TSTR, (ioaddr + XP_ADDR));
3593
if (inb(ioaddr + XP_DATA) != 0) {
3594
printk("STALLION: sc26198 not responding, "
3595
"brd=%d panel=%d chip=%d\n",
3596
panelp->brdnr, panelp->panelnr, i);
3599
chipmask |= (0x1 << i);
3600
outb(GCCR, (ioaddr + XP_ADDR));
3601
outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
3602
outb(WDTRCR, (ioaddr + XP_ADDR));
3603
outb(0xff, (ioaddr + XP_DATA));
3606
BRDDISABLE(panelp->brdnr);
3610
/*****************************************************************************/
3613
* Initialize hardware specific port registers.
3616
static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3618
pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3621
if ((brdp == NULL) || (panelp == NULL) ||
3625
portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3626
portp->uartaddr = (portp->portnr & 0x07) << 4;
3627
portp->pagenr = panelp->pagenr;
3630
BRDENABLE(portp->brdnr, portp->pagenr);
3631
stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3632
BRDDISABLE(portp->brdnr);
3635
/*****************************************************************************/
3638
* Set up the sc26198 registers for a port based on the termios port
3642
static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
3644
struct stlbrd *brdp;
3645
unsigned long flags;
3646
unsigned int baudrate;
3647
unsigned char mr0, mr1, mr2, clk;
3648
unsigned char imron, imroff, iopr, ipr;
3658
brdp = stl_brds[portp->brdnr];
3663
* Set up the RX char ignore mask with those RX error types we
3666
portp->rxignoremsk = 0;
3667
if (tiosp->c_iflag & IGNPAR)
3668
portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3670
if (tiosp->c_iflag & IGNBRK)
3671
portp->rxignoremsk |= SR_RXBREAK;
3673
portp->rxmarkmsk = SR_RXOVERRUN;
3674
if (tiosp->c_iflag & (INPCK | PARMRK))
3675
portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3676
if (tiosp->c_iflag & BRKINT)
3677
portp->rxmarkmsk |= SR_RXBREAK;
3680
* Go through the char size, parity and stop bits and set all the
3681
* option register appropriately.
3683
switch (tiosp->c_cflag & CSIZE) {
3698
if (tiosp->c_cflag & CSTOPB)
3703
if (tiosp->c_cflag & PARENB) {
3704
if (tiosp->c_cflag & PARODD)
3705
mr1 |= (MR1_PARENB | MR1_PARODD);
3707
mr1 |= (MR1_PARENB | MR1_PAREVEN);
3711
mr1 |= MR1_ERRBLOCK;
3714
* Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3715
* space for hardware flow control and the like. This should be set to
3718
mr2 |= MR2_RXFIFOHALF;
3721
* Calculate the baud rate timers. For now we will just assume that
3722
* the input and output baud are the same. The sc26198 has a fixed
3723
* baud rate table, so only discrete baud rates possible.
3725
baudrate = tiosp->c_cflag & CBAUD;
3726
if (baudrate & CBAUDEX) {
3727
baudrate &= ~CBAUDEX;
3728
if ((baudrate < 1) || (baudrate > 4))
3729
tiosp->c_cflag &= ~CBAUDEX;
3733
baudrate = stl_baudrates[baudrate];
3734
if ((tiosp->c_cflag & CBAUD) == B38400) {
3735
if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3737
else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3739
else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3741
else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3743
else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3744
baudrate = (portp->baud_base / portp->custom_divisor);
3746
if (baudrate > STL_SC26198MAXBAUD)
3747
baudrate = STL_SC26198MAXBAUD;
3750
for (clk = 0; clk < SC26198_NRBAUDS; clk++)
3751
if (baudrate <= sc26198_baudtable[clk])
3755
* Check what form of modem signaling is required and set it up.
3757
if (tiosp->c_cflag & CLOCAL) {
3758
portp->port.flags &= ~ASYNC_CHECK_CD;
3760
iopr |= IOPR_DCDCOS;
3762
portp->port.flags |= ASYNC_CHECK_CD;
3766
* Setup sc26198 enhanced modes if we can. In particular we want to
3767
* handle as much of the flow control as possible automatically. As
3768
* well as saving a few CPU cycles it will also greatly improve flow
3769
* control reliability.
3771
if (tiosp->c_iflag & IXON) {
3772
mr0 |= MR0_SWFTX | MR0_SWFT;
3773
imron |= IR_XONXOFF;
3775
imroff |= IR_XONXOFF;
3777
if (tiosp->c_iflag & IXOFF)
3780
if (tiosp->c_cflag & CRTSCTS) {
3786
* All sc26198 register values calculated so go through and set
3790
pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3791
portp->portnr, portp->panelnr, portp->brdnr);
3792
pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
3793
pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
3794
pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3795
tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3796
tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3798
spin_lock_irqsave(&brd_lock, flags);
3799
BRDENABLE(portp->brdnr, portp->pagenr);
3800
stl_sc26198setreg(portp, IMR, 0);
3801
stl_sc26198updatereg(portp, MR0, mr0);
3802
stl_sc26198updatereg(portp, MR1, mr1);
3803
stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
3804
stl_sc26198updatereg(portp, MR2, mr2);
3805
stl_sc26198updatereg(portp, IOPIOR,
3806
((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
3809
stl_sc26198setreg(portp, TXCSR, clk);
3810
stl_sc26198setreg(portp, RXCSR, clk);
3813
stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
3814
stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
3816
ipr = stl_sc26198getreg(portp, IPR);
3818
portp->sigs &= ~TIOCM_CD;
3820
portp->sigs |= TIOCM_CD;
3822
portp->imr = (portp->imr & ~imroff) | imron;
3823
stl_sc26198setreg(portp, IMR, portp->imr);
3824
BRDDISABLE(portp->brdnr);
3825
spin_unlock_irqrestore(&brd_lock, flags);
3828
/*****************************************************************************/
3831
* Set the state of the DTR and RTS signals.
3834
static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
3836
unsigned char iopioron, iopioroff;
3837
unsigned long flags;
3839
pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
3845
iopioroff |= IPR_DTR;
3847
iopioron |= IPR_DTR;
3849
iopioroff |= IPR_RTS;
3851
iopioron |= IPR_RTS;
3853
spin_lock_irqsave(&brd_lock, flags);
3854
BRDENABLE(portp->brdnr, portp->pagenr);
3855
stl_sc26198setreg(portp, IOPIOR,
3856
((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
3857
BRDDISABLE(portp->brdnr);
3858
spin_unlock_irqrestore(&brd_lock, flags);
3861
/*****************************************************************************/
3864
* Return the state of the signals.
3867
static int stl_sc26198getsignals(struct stlport *portp)
3870
unsigned long flags;
3873
pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
3875
spin_lock_irqsave(&brd_lock, flags);
3876
BRDENABLE(portp->brdnr, portp->pagenr);
3877
ipr = stl_sc26198getreg(portp, IPR);
3878
BRDDISABLE(portp->brdnr);
3879
spin_unlock_irqrestore(&brd_lock, flags);
3882
sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
3883
sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
3884
sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
3885
sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
3890
/*****************************************************************************/
3893
* Enable/Disable the Transmitter and/or Receiver.
3896
static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
3899
unsigned long flags;
3901
pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
3903
ccr = portp->crenable;
3905
ccr &= ~CR_TXENABLE;
3909
ccr &= ~CR_RXENABLE;
3913
spin_lock_irqsave(&brd_lock, flags);
3914
BRDENABLE(portp->brdnr, portp->pagenr);
3915
stl_sc26198setreg(portp, SCCR, ccr);
3916
BRDDISABLE(portp->brdnr);
3917
portp->crenable = ccr;
3918
spin_unlock_irqrestore(&brd_lock, flags);
3921
/*****************************************************************************/
3924
* Start/stop the Transmitter and/or Receiver.
3927
static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
3930
unsigned long flags;
3932
pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3940
imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
3942
imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
3944
spin_lock_irqsave(&brd_lock, flags);
3945
BRDENABLE(portp->brdnr, portp->pagenr);
3946
stl_sc26198setreg(portp, IMR, imr);
3947
BRDDISABLE(portp->brdnr);
3950
set_bit(ASYI_TXBUSY, &portp->istate);
3951
spin_unlock_irqrestore(&brd_lock, flags);
3954
/*****************************************************************************/
3957
* Disable all interrupts from this port.
3960
static void stl_sc26198disableintrs(struct stlport *portp)
3962
unsigned long flags;
3964
pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
3966
spin_lock_irqsave(&brd_lock, flags);
3967
BRDENABLE(portp->brdnr, portp->pagenr);
3969
stl_sc26198setreg(portp, IMR, 0);
3970
BRDDISABLE(portp->brdnr);
3971
spin_unlock_irqrestore(&brd_lock, flags);
3974
/*****************************************************************************/
3976
static void stl_sc26198sendbreak(struct stlport *portp, int len)
3978
unsigned long flags;
3980
pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
3982
spin_lock_irqsave(&brd_lock, flags);
3983
BRDENABLE(portp->brdnr, portp->pagenr);
3985
stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
3986
portp->stats.txbreaks++;
3988
stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
3990
BRDDISABLE(portp->brdnr);
3991
spin_unlock_irqrestore(&brd_lock, flags);
3994
/*****************************************************************************/
3997
* Take flow control actions...
4000
static void stl_sc26198flowctrl(struct stlport *portp, int state)
4002
struct tty_struct *tty;
4003
unsigned long flags;
4006
pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4010
tty = tty_port_tty_get(&portp->port);
4014
spin_lock_irqsave(&brd_lock, flags);
4015
BRDENABLE(portp->brdnr, portp->pagenr);
4018
if (tty->termios->c_iflag & IXOFF) {
4019
mr0 = stl_sc26198getreg(portp, MR0);
4020
stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4021
stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4023
portp->stats.rxxon++;
4024
stl_sc26198wait(portp);
4025
stl_sc26198setreg(portp, MR0, mr0);
4028
* Question: should we return RTS to what it was before? It may
4029
* have been set by an ioctl... Suppose not, since if you have
4030
* hardware flow control set then it is pretty silly to go and
4031
* set the RTS line by hand.
4033
if (tty->termios->c_cflag & CRTSCTS) {
4034
stl_sc26198setreg(portp, MR1,
4035
(stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4036
stl_sc26198setreg(portp, IOPIOR,
4037
(stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4038
portp->stats.rxrtson++;
4041
if (tty->termios->c_iflag & IXOFF) {
4042
mr0 = stl_sc26198getreg(portp, MR0);
4043
stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4044
stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4046
portp->stats.rxxoff++;
4047
stl_sc26198wait(portp);
4048
stl_sc26198setreg(portp, MR0, mr0);
4050
if (tty->termios->c_cflag & CRTSCTS) {
4051
stl_sc26198setreg(portp, MR1,
4052
(stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4053
stl_sc26198setreg(portp, IOPIOR,
4054
(stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4055
portp->stats.rxrtsoff++;
4059
BRDDISABLE(portp->brdnr);
4060
spin_unlock_irqrestore(&brd_lock, flags);
4064
/*****************************************************************************/
4067
* Send a flow control character.
4070
static void stl_sc26198sendflow(struct stlport *portp, int state)
4072
struct tty_struct *tty;
4073
unsigned long flags;
4076
pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4080
tty = tty_port_tty_get(&portp->port);
4084
spin_lock_irqsave(&brd_lock, flags);
4085
BRDENABLE(portp->brdnr, portp->pagenr);
4087
mr0 = stl_sc26198getreg(portp, MR0);
4088
stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4089
stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4091
portp->stats.rxxon++;
4092
stl_sc26198wait(portp);
4093
stl_sc26198setreg(portp, MR0, mr0);
4095
mr0 = stl_sc26198getreg(portp, MR0);
4096
stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4097
stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4099
portp->stats.rxxoff++;
4100
stl_sc26198wait(portp);
4101
stl_sc26198setreg(portp, MR0, mr0);
4103
BRDDISABLE(portp->brdnr);
4104
spin_unlock_irqrestore(&brd_lock, flags);
4108
/*****************************************************************************/
4110
static void stl_sc26198flush(struct stlport *portp)
4112
unsigned long flags;
4114
pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4119
spin_lock_irqsave(&brd_lock, flags);
4120
BRDENABLE(portp->brdnr, portp->pagenr);
4121
stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4122
stl_sc26198setreg(portp, SCCR, portp->crenable);
4123
BRDDISABLE(portp->brdnr);
4124
portp->tx.tail = portp->tx.head;
4125
spin_unlock_irqrestore(&brd_lock, flags);
4128
/*****************************************************************************/
4131
* Return the current state of data flow on this port. This is only
4132
* really interesting when determining if data has fully completed
4133
* transmission or not... The sc26198 interrupt scheme cannot
4134
* determine when all data has actually drained, so we need to
4135
* check the port statusy register to be sure.
4138
static int stl_sc26198datastate(struct stlport *portp)
4140
unsigned long flags;
4143
pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4147
if (test_bit(ASYI_TXBUSY, &portp->istate))
4150
spin_lock_irqsave(&brd_lock, flags);
4151
BRDENABLE(portp->brdnr, portp->pagenr);
4152
sr = stl_sc26198getreg(portp, SR);
4153
BRDDISABLE(portp->brdnr);
4154
spin_unlock_irqrestore(&brd_lock, flags);
4156
return (sr & SR_TXEMPTY) ? 0 : 1;
4159
/*****************************************************************************/
4162
* Delay for a small amount of time, to give the sc26198 a chance
4163
* to process a command...
4166
static void stl_sc26198wait(struct stlport *portp)
4170
pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4175
for (i = 0; i < 20; i++)
4176
stl_sc26198getglobreg(portp, TSTR);
4179
/*****************************************************************************/
4182
* If we are TX flow controlled and in IXANY mode then we may
4183
* need to unflow control here. We gotta do this because of the
4184
* automatic flow control modes of the sc26198.
4187
static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4191
mr0 = stl_sc26198getreg(portp, MR0);
4192
stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4193
stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4194
stl_sc26198wait(portp);
4195
stl_sc26198setreg(portp, MR0, mr0);
4196
clear_bit(ASYI_TXFLOWED, &portp->istate);
4199
/*****************************************************************************/
4202
* Interrupt service routine for sc26198 panels.
4205
static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4207
struct stlport *portp;
4210
spin_lock(&brd_lock);
4213
* Work around bug in sc26198 chip... Cannot have A6 address
4214
* line of UART high, else iack will be returned as 0.
4216
outb(0, (iobase + 1));
4218
iack = inb(iobase + XP_IACK);
4219
portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4221
if (iack & IVR_RXDATA)
4222
stl_sc26198rxisr(portp, iack);
4223
else if (iack & IVR_TXDATA)
4224
stl_sc26198txisr(portp);
4226
stl_sc26198otherisr(portp, iack);
4228
spin_unlock(&brd_lock);
4231
/*****************************************************************************/
4234
* Transmit interrupt handler. This has gotta be fast! Handling TX
4235
* chars is pretty simple, stuff as many as possible from the TX buffer
4236
* into the sc26198 FIFO.
4237
* In practice it is possible that interrupts are enabled but that the
4238
* port has been hung up. Need to handle not having any TX buffer here,
4239
* this is done by using the side effect that head and tail will also
4240
* be NULL if the buffer has been freed.
4243
static void stl_sc26198txisr(struct stlport *portp)
4245
struct tty_struct *tty;
4246
unsigned int ioaddr;
4251
pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4253
ioaddr = portp->ioaddr;
4254
head = portp->tx.head;
4255
tail = portp->tx.tail;
4256
len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4257
if ((len == 0) || ((len < STL_TXBUFLOW) &&
4258
(test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4259
set_bit(ASYI_TXLOW, &portp->istate);
4260
tty = tty_port_tty_get(&portp->port);
4268
outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4269
mr0 = inb(ioaddr + XP_DATA);
4270
if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4271
portp->imr &= ~IR_TXRDY;
4272
outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4273
outb(portp->imr, (ioaddr + XP_DATA));
4274
clear_bit(ASYI_TXBUSY, &portp->istate);
4276
mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4277
outb(mr0, (ioaddr + XP_DATA));
4280
len = min(len, SC26198_TXFIFOSIZE);
4281
portp->stats.txtotal += len;
4282
stlen = min_t(unsigned int, len,
4283
(portp->tx.buf + STL_TXBUFSIZE) - tail);
4284
outb(GTXFIFO, (ioaddr + XP_ADDR));
4285
outsb((ioaddr + XP_DATA), tail, stlen);
4288
if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4289
tail = portp->tx.buf;
4291
outsb((ioaddr + XP_DATA), tail, len);
4294
portp->tx.tail = tail;
4298
/*****************************************************************************/
4301
* Receive character interrupt handler. Determine if we have good chars
4302
* or bad chars and then process appropriately. Good chars are easy
4303
* just shove the lot into the RX buffer and set all status byte to 0.
4304
* If a bad RX char then process as required. This routine needs to be
4305
* fast! In practice it is possible that we get an interrupt on a port
4306
* that is closed. This can happen on hangups - since they completely
4307
* shutdown a port not in user context. Need to handle this case.
4310
static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4312
struct tty_struct *tty;
4313
unsigned int len, buflen, ioaddr;
4315
pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4317
tty = tty_port_tty_get(&portp->port);
4318
ioaddr = portp->ioaddr;
4319
outb(GIBCR, (ioaddr + XP_ADDR));
4320
len = inb(ioaddr + XP_DATA) + 1;
4322
if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4323
if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4324
len = min_t(unsigned int, len, sizeof(stl_unwanted));
4325
outb(GRXFIFO, (ioaddr + XP_ADDR));
4326
insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4327
portp->stats.rxlost += len;
4328
portp->stats.rxtotal += len;
4330
len = min(len, buflen);
4333
outb(GRXFIFO, (ioaddr + XP_ADDR));
4334
tty_prepare_flip_string(tty, &ptr, len);
4335
insb((ioaddr + XP_DATA), ptr, len);
4336
tty_schedule_flip(tty);
4337
portp->stats.rxtotal += len;
4341
stl_sc26198rxbadchars(portp);
4345
* If we are TX flow controlled and in IXANY mode then we may need
4346
* to unflow control here. We gotta do this because of the automatic
4347
* flow control modes of the sc26198.
4349
if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4350
if ((tty != NULL) &&
4351
(tty->termios != NULL) &&
4352
(tty->termios->c_iflag & IXANY)) {
4353
stl_sc26198txunflow(portp, tty);
4359
/*****************************************************************************/
4362
* Process an RX bad character.
4365
static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4367
struct tty_struct *tty;
4368
unsigned int ioaddr;
4370
tty = tty_port_tty_get(&portp->port);
4371
ioaddr = portp->ioaddr;
4373
if (status & SR_RXPARITY)
4374
portp->stats.rxparity++;
4375
if (status & SR_RXFRAMING)
4376
portp->stats.rxframing++;
4377
if (status & SR_RXOVERRUN)
4378
portp->stats.rxoverrun++;
4379
if (status & SR_RXBREAK)
4380
portp->stats.rxbreaks++;
4382
if ((tty != NULL) &&
4383
((portp->rxignoremsk & status) == 0)) {
4384
if (portp->rxmarkmsk & status) {
4385
if (status & SR_RXBREAK) {
4387
if (portp->port.flags & ASYNC_SAK) {
4389
BRDENABLE(portp->brdnr, portp->pagenr);
4391
} else if (status & SR_RXPARITY)
4392
status = TTY_PARITY;
4393
else if (status & SR_RXFRAMING)
4395
else if(status & SR_RXOVERRUN)
4396
status = TTY_OVERRUN;
4402
tty_insert_flip_char(tty, ch, status);
4403
tty_schedule_flip(tty);
4406
portp->stats.rxtotal++;
4411
/*****************************************************************************/
4414
* Process all characters in the RX FIFO of the UART. Check all char
4415
* status bytes as well, and process as required. We need to check
4416
* all bytes in the FIFO, in case some more enter the FIFO while we
4417
* are here. To get the exact character error type we need to switch
4418
* into CHAR error mode (that is why we need to make sure we empty
4422
static void stl_sc26198rxbadchars(struct stlport *portp)
4424
unsigned char status, mr1;
4428
* To get the precise error type for each character we must switch
4429
* back into CHAR error mode.
4431
mr1 = stl_sc26198getreg(portp, MR1);
4432
stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4434
while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4435
stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4436
ch = stl_sc26198getreg(portp, RXFIFO);
4437
stl_sc26198rxbadch(portp, status, ch);
4441
* To get correct interrupt class we must switch back into BLOCK
4444
stl_sc26198setreg(portp, MR1, mr1);
4447
/*****************************************************************************/
4450
* Other interrupt handler. This includes modem signals, flow
4451
* control actions, etc. Most stuff is left to off-level interrupt
4455
static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
4457
unsigned char cir, ipr, xisr;
4459
pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
4461
cir = stl_sc26198getglobreg(portp, CIR);
4463
switch (cir & CIR_SUBTYPEMASK) {
4465
ipr = stl_sc26198getreg(portp, IPR);
4466
if (ipr & IPR_DCDCHANGE) {
4467
stl_cd_change(portp);
4468
portp->stats.modem++;
4471
case CIR_SUBXONXOFF:
4472
xisr = stl_sc26198getreg(portp, XISR);
4473
if (xisr & XISR_RXXONGOT) {
4474
set_bit(ASYI_TXFLOWED, &portp->istate);
4475
portp->stats.txxoff++;
4477
if (xisr & XISR_RXXOFFGOT) {
4478
clear_bit(ASYI_TXFLOWED, &portp->istate);
4479
portp->stats.txxon++;
4483
stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4484
stl_sc26198rxbadchars(portp);
4491
static void stl_free_isabrds(void)
4493
struct stlbrd *brdp;
4496
for (i = 0; i < stl_nrbrds; i++) {
4497
if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4500
free_irq(brdp->irq, brdp);
4502
stl_cleanup_panels(brdp);
4504
release_region(brdp->ioaddr1, brdp->iosize1);
4505
if (brdp->iosize2 > 0)
4506
release_region(brdp->ioaddr2, brdp->iosize2);
4514
* Loadable module initialization stuff.
4516
static int __init stallion_module_init(void)
4518
struct stlbrd *brdp;
4519
struct stlconf conf;
4523
printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4525
spin_lock_init(&stallion_lock);
4526
spin_lock_init(&brd_lock);
4528
stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4534
stl_serial->owner = THIS_MODULE;
4535
stl_serial->driver_name = stl_drvname;
4536
stl_serial->name = "ttyE";
4537
stl_serial->major = STL_SERIALMAJOR;
4538
stl_serial->minor_start = 0;
4539
stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
4540
stl_serial->subtype = SERIAL_TYPE_NORMAL;
4541
stl_serial->init_termios = stl_deftermios;
4542
stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
4543
tty_set_operations(stl_serial, &stl_ops);
4545
retval = tty_register_driver(stl_serial);
4547
printk("STALLION: failed to register serial driver\n");
4552
* Find any dynamically supported boards. That is via module load
4555
for (i = stl_nrbrds; i < stl_nargs; i++) {
4556
memset(&conf, 0, sizeof(conf));
4557
if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
4559
if ((brdp = stl_allocbrd()) == NULL)
4562
brdp->brdtype = conf.brdtype;
4563
brdp->ioaddr1 = conf.ioaddr1;
4564
brdp->ioaddr2 = conf.ioaddr2;
4565
brdp->irq = conf.irq;
4566
brdp->irqtype = conf.irqtype;
4567
stl_brds[brdp->brdnr] = brdp;
4568
if (stl_brdinit(brdp)) {
4569
stl_brds[brdp->brdnr] = NULL;
4572
for (j = 0; j < brdp->nrports; j++)
4573
tty_register_device(stl_serial,
4574
brdp->brdnr * STL_MAXPORTS + j, NULL);
4579
/* this has to be _after_ isa finding because of locking */
4580
retval = pci_register_driver(&stl_pcidriver);
4581
if (retval && stl_nrbrds == 0) {
4582
printk(KERN_ERR "STALLION: can't register pci driver\n");
4587
* Set up a character driver for per board stuff. This is mainly used
4588
* to do stats ioctls on the ports.
4590
if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
4591
printk("STALLION: failed to register serial board device\n");
4593
stallion_class = class_create(THIS_MODULE, "staliomem");
4594
if (IS_ERR(stallion_class))
4595
printk("STALLION: failed to create class\n");
4596
for (i = 0; i < 4; i++)
4597
device_create(stallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i),
4598
NULL, "staliomem%d", i);
4602
tty_unregister_driver(stl_serial);
4604
put_tty_driver(stl_serial);
4609
static void __exit stallion_module_exit(void)
4611
struct stlbrd *brdp;
4614
pr_debug("cleanup_module()\n");
4616
printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
4620
* Free up all allocated resources used by the ports. This includes
4621
* memory and interrupts. As part of this process we will also do
4622
* a hangup on every open port - to try to flush out any processes
4623
* hanging onto ports.
4625
for (i = 0; i < stl_nrbrds; i++) {
4626
if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4628
for (j = 0; j < brdp->nrports; j++)
4629
tty_unregister_device(stl_serial,
4630
brdp->brdnr * STL_MAXPORTS + j);
4633
for (i = 0; i < 4; i++)
4634
device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4635
unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
4636
class_destroy(stallion_class);
4638
pci_unregister_driver(&stl_pcidriver);
4642
tty_unregister_driver(stl_serial);
4643
put_tty_driver(stl_serial);
4646
module_init(stallion_module_init);
4647
module_exit(stallion_module_exit);
4649
MODULE_AUTHOR("Greg Ungerer");
4650
MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4651
MODULE_LICENSE("GPL");