[PATCH] devfs: Remove devfs_mk_cdev() function from the kernel tree
[deliverable/linux.git] / drivers / char / stallion.c
CommitLineData
1da177e4
LT
1/*****************************************************************************/
2
3/*
4 * stallion.c -- stallion multiport serial driver.
5 *
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
8 *
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
11 *
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.
16 *
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.
21 *
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.
25 */
26
27/*****************************************************************************/
28
29#include <linux/config.h>
30#include <linux/module.h>
31#include <linux/slab.h>
32#include <linux/interrupt.h>
33#include <linux/tty.h>
34#include <linux/tty_flip.h>
35#include <linux/serial.h>
36#include <linux/cd1400.h>
37#include <linux/sc26198.h>
38#include <linux/comstats.h>
39#include <linux/stallion.h>
40#include <linux/ioport.h>
41#include <linux/init.h>
42#include <linux/smp_lock.h>
43#include <linux/devfs_fs_kernel.h>
44#include <linux/device.h>
45#include <linux/delay.h>
46
47#include <asm/io.h>
48#include <asm/uaccess.h>
49
50#ifdef CONFIG_PCI
51#include <linux/pci.h>
52#endif
53
54/*****************************************************************************/
55
56/*
57 * Define different board types. Use the standard Stallion "assigned"
58 * board numbers. Boards supported in this driver are abbreviated as
59 * EIO = EasyIO and ECH = EasyConnection 8/32.
60 */
61#define BRD_EASYIO 20
62#define BRD_ECH 21
63#define BRD_ECHMC 22
64#define BRD_ECHPCI 26
65#define BRD_ECH64PCI 27
66#define BRD_EASYIOPCI 28
67
68/*
69 * Define a configuration structure to hold the board configuration.
70 * Need to set this up in the code (for now) with the boards that are
71 * to be configured into the system. This is what needs to be modified
72 * when adding/removing/modifying boards. Each line entry in the
73 * stl_brdconf[] array is a board. Each line contains io/irq/memory
74 * ranges for that board (as well as what type of board it is).
75 * Some examples:
76 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
77 * This line would configure an EasyIO board (4 or 8, no difference),
78 * at io address 2a0 and irq 10.
79 * Another example:
80 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
81 * This line will configure an EasyConnection 8/32 board at primary io
82 * address 2a8, secondary io address 280 and irq 12.
83 * Enter as many lines into this array as you want (only the first 4
84 * will actually be used!). Any combination of EasyIO and EasyConnection
85 * boards can be specified. EasyConnection 8/32 boards can share their
86 * secondary io addresses between each other.
87 *
88 * NOTE: there is no need to put any entries in this table for PCI
89 * boards. They will be found automatically by the driver - provided
90 * PCI BIOS32 support is compiled into the kernel.
91 */
92
93typedef struct {
94 int brdtype;
95 int ioaddr1;
96 int ioaddr2;
97 unsigned long memaddr;
98 int irq;
99 int irqtype;
100} stlconf_t;
101
102static stlconf_t stl_brdconf[] = {
103 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
104};
105
fe971071 106static int stl_nrbrds = ARRAY_SIZE(stl_brdconf);
1da177e4
LT
107
108/*****************************************************************************/
109
110/*
111 * Define some important driver characteristics. Device major numbers
112 * allocated as per Linux Device Registry.
113 */
114#ifndef STL_SIOMEMMAJOR
115#define STL_SIOMEMMAJOR 28
116#endif
117#ifndef STL_SERIALMAJOR
118#define STL_SERIALMAJOR 24
119#endif
120#ifndef STL_CALLOUTMAJOR
121#define STL_CALLOUTMAJOR 25
122#endif
123
124/*
125 * Set the TX buffer size. Bigger is better, but we don't want
126 * to chew too much memory with buffers!
127 */
128#define STL_TXBUFLOW 512
129#define STL_TXBUFSIZE 4096
130
131/*****************************************************************************/
132
133/*
134 * Define our local driver identity first. Set up stuff to deal with
135 * all the local structures required by a serial tty driver.
136 */
137static char *stl_drvtitle = "Stallion Multiport Serial Driver";
138static char *stl_drvname = "stallion";
139static char *stl_drvversion = "5.6.0";
140
141static struct tty_driver *stl_serial;
142
143/*
144 * We will need to allocate a temporary write buffer for chars that
145 * come direct from user space. The problem is that a copy from user
146 * space might cause a page fault (typically on a system that is
147 * swapping!). All ports will share one buffer - since if the system
148 * is already swapping a shared buffer won't make things any worse.
149 */
150static char *stl_tmpwritebuf;
1da177e4
LT
151
152/*
153 * Define a local default termios struct. All ports will be created
154 * with this termios initially. Basically all it defines is a raw port
155 * at 9600, 8 data bits, 1 stop bit.
156 */
157static struct termios stl_deftermios = {
158 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
159 .c_cc = INIT_C_CC,
160};
161
162/*
163 * Define global stats structures. Not used often, and can be
164 * re-used for each stats call.
165 */
166static comstats_t stl_comstats;
167static combrd_t stl_brdstats;
168static stlbrd_t stl_dummybrd;
169static stlport_t stl_dummyport;
170
171/*
172 * Define global place to put buffer overflow characters.
173 */
174static char stl_unwanted[SC26198_RXFIFOSIZE];
175
176/*****************************************************************************/
177
178static stlbrd_t *stl_brds[STL_MAXBRDS];
179
180/*
181 * Per board state flags. Used with the state field of the board struct.
182 * Not really much here!
183 */
184#define BRD_FOUND 0x1
185
186/*
187 * Define the port structure istate flags. These set of flags are
188 * modified at interrupt time - so setting and reseting them needs
189 * to be atomic. Use the bit clear/setting routines for this.
190 */
191#define ASYI_TXBUSY 1
192#define ASYI_TXLOW 2
193#define ASYI_DCDCHANGE 3
194#define ASYI_TXFLOWED 4
195
196/*
197 * Define an array of board names as printable strings. Handy for
198 * referencing boards when printing trace and stuff.
199 */
200static char *stl_brdnames[] = {
201 (char *) NULL,
202 (char *) NULL,
203 (char *) NULL,
204 (char *) NULL,
205 (char *) NULL,
206 (char *) NULL,
207 (char *) NULL,
208 (char *) NULL,
209 (char *) NULL,
210 (char *) NULL,
211 (char *) NULL,
212 (char *) NULL,
213 (char *) NULL,
214 (char *) NULL,
215 (char *) NULL,
216 (char *) NULL,
217 (char *) NULL,
218 (char *) NULL,
219 (char *) NULL,
220 (char *) NULL,
221 "EasyIO",
222 "EC8/32-AT",
223 "EC8/32-MC",
224 (char *) NULL,
225 (char *) NULL,
226 (char *) NULL,
227 "EC8/32-PCI",
228 "EC8/64-PCI",
229 "EasyIO-PCI",
230};
231
232/*****************************************************************************/
233
234/*
235 * Define some string labels for arguments passed from the module
236 * load line. These allow for easy board definitions, and easy
237 * modification of the io, memory and irq resoucres.
238 */
239static int stl_nargs = 0;
240static char *board0[4];
241static char *board1[4];
242static char *board2[4];
243static char *board3[4];
244
245static char **stl_brdsp[] = {
246 (char **) &board0,
247 (char **) &board1,
248 (char **) &board2,
249 (char **) &board3
250};
251
252/*
253 * Define a set of common board names, and types. This is used to
254 * parse any module arguments.
255 */
256
257typedef struct stlbrdtype {
258 char *name;
259 int type;
260} stlbrdtype_t;
261
262static stlbrdtype_t stl_brdstr[] = {
263 { "easyio", BRD_EASYIO },
264 { "eio", BRD_EASYIO },
265 { "20", BRD_EASYIO },
266 { "ec8/32", BRD_ECH },
267 { "ec8/32-at", BRD_ECH },
268 { "ec8/32-isa", BRD_ECH },
269 { "ech", BRD_ECH },
270 { "echat", BRD_ECH },
271 { "21", BRD_ECH },
272 { "ec8/32-mc", BRD_ECHMC },
273 { "ec8/32-mca", BRD_ECHMC },
274 { "echmc", BRD_ECHMC },
275 { "echmca", BRD_ECHMC },
276 { "22", BRD_ECHMC },
277 { "ec8/32-pc", BRD_ECHPCI },
278 { "ec8/32-pci", BRD_ECHPCI },
279 { "26", BRD_ECHPCI },
280 { "ec8/64-pc", BRD_ECH64PCI },
281 { "ec8/64-pci", BRD_ECH64PCI },
282 { "ech-pci", BRD_ECH64PCI },
283 { "echpci", BRD_ECH64PCI },
284 { "echpc", BRD_ECH64PCI },
285 { "27", BRD_ECH64PCI },
286 { "easyio-pc", BRD_EASYIOPCI },
287 { "easyio-pci", BRD_EASYIOPCI },
288 { "eio-pci", BRD_EASYIOPCI },
289 { "eiopci", BRD_EASYIOPCI },
290 { "28", BRD_EASYIOPCI },
291};
292
293/*
294 * Define the module agruments.
295 */
296MODULE_AUTHOR("Greg Ungerer");
297MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
298MODULE_LICENSE("GPL");
299
300module_param_array(board0, charp, &stl_nargs, 0);
301MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
302module_param_array(board1, charp, &stl_nargs, 0);
303MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
304module_param_array(board2, charp, &stl_nargs, 0);
305MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
306module_param_array(board3, charp, &stl_nargs, 0);
307MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
308
309/*****************************************************************************/
310
311/*
312 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
313 * to the directly accessible io ports of these boards (not the uarts -
314 * they are in cd1400.h and sc26198.h).
315 */
316#define EIO_8PORTRS 0x04
317#define EIO_4PORTRS 0x05
318#define EIO_8PORTDI 0x00
319#define EIO_8PORTM 0x06
320#define EIO_MK3 0x03
321#define EIO_IDBITMASK 0x07
322
323#define EIO_BRDMASK 0xf0
324#define ID_BRD4 0x10
325#define ID_BRD8 0x20
326#define ID_BRD16 0x30
327
328#define EIO_INTRPEND 0x08
329#define EIO_INTEDGE 0x00
330#define EIO_INTLEVEL 0x08
331#define EIO_0WS 0x10
332
333#define ECH_ID 0xa0
334#define ECH_IDBITMASK 0xe0
335#define ECH_BRDENABLE 0x08
336#define ECH_BRDDISABLE 0x00
337#define ECH_INTENABLE 0x01
338#define ECH_INTDISABLE 0x00
339#define ECH_INTLEVEL 0x02
340#define ECH_INTEDGE 0x00
341#define ECH_INTRPEND 0x01
342#define ECH_BRDRESET 0x01
343
344#define ECHMC_INTENABLE 0x01
345#define ECHMC_BRDRESET 0x02
346
347#define ECH_PNLSTATUS 2
348#define ECH_PNL16PORT 0x20
349#define ECH_PNLIDMASK 0x07
350#define ECH_PNLXPID 0x40
351#define ECH_PNLINTRPEND 0x80
352
353#define ECH_ADDR2MASK 0x1e0
354
355/*
356 * Define the vector mapping bits for the programmable interrupt board
357 * hardware. These bits encode the interrupt for the board to use - it
358 * is software selectable (except the EIO-8M).
359 */
360static unsigned char stl_vecmap[] = {
361 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
362 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
363};
364
365/*
366 * Set up enable and disable macros for the ECH boards. They require
367 * the secondary io address space to be activated and deactivated.
368 * This way all ECH boards can share their secondary io region.
369 * If this is an ECH-PCI board then also need to set the page pointer
370 * to point to the correct page.
371 */
372#define BRDENABLE(brdnr,pagenr) \
373 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
374 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
375 stl_brds[(brdnr)]->ioctrl); \
376 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
377 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
378
379#define BRDDISABLE(brdnr) \
380 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
381 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
382 stl_brds[(brdnr)]->ioctrl);
383
384#define STL_CD1400MAXBAUD 230400
385#define STL_SC26198MAXBAUD 460800
386
387#define STL_BAUDBASE 115200
388#define STL_CLOSEDELAY (5 * HZ / 10)
389
390/*****************************************************************************/
391
392#ifdef CONFIG_PCI
393
394/*
395 * Define the Stallion PCI vendor and device IDs.
396 */
397#ifndef PCI_VENDOR_ID_STALLION
398#define PCI_VENDOR_ID_STALLION 0x124d
399#endif
400#ifndef PCI_DEVICE_ID_ECHPCI832
401#define PCI_DEVICE_ID_ECHPCI832 0x0000
402#endif
403#ifndef PCI_DEVICE_ID_ECHPCI864
404#define PCI_DEVICE_ID_ECHPCI864 0x0002
405#endif
406#ifndef PCI_DEVICE_ID_EIOPCI
407#define PCI_DEVICE_ID_EIOPCI 0x0003
408#endif
409
410/*
411 * Define structure to hold all Stallion PCI boards.
412 */
413typedef struct stlpcibrd {
414 unsigned short vendid;
415 unsigned short devid;
416 int brdtype;
417} stlpcibrd_t;
418
419static stlpcibrd_t stl_pcibrds[] = {
420 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
421 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
422 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
423 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
424};
425
fe971071 426static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
1da177e4
LT
427
428#endif
429
430/*****************************************************************************/
431
432/*
433 * Define macros to extract a brd/port number from a minor number.
434 */
435#define MINOR2BRD(min) (((min) & 0xc0) >> 6)
436#define MINOR2PORT(min) ((min) & 0x3f)
437
438/*
439 * Define a baud rate table that converts termios baud rate selector
440 * into the actual baud rate value. All baud rate calculations are
441 * based on the actual baud rate required.
442 */
443static unsigned int stl_baudrates[] = {
444 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
445 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
446};
447
448/*
449 * Define some handy local macros...
450 */
451#undef MIN
452#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
453
454#undef TOLOWER
455#define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
456
457/*****************************************************************************/
458
459/*
460 * Declare all those functions in this driver!
461 */
462
463static void stl_argbrds(void);
464static int stl_parsebrd(stlconf_t *confp, char **argp);
465
466static unsigned long stl_atol(char *str);
467
408b664a 468static int stl_init(void);
1da177e4
LT
469static int stl_open(struct tty_struct *tty, struct file *filp);
470static void stl_close(struct tty_struct *tty, struct file *filp);
471static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
472static void stl_putchar(struct tty_struct *tty, unsigned char ch);
473static void stl_flushchars(struct tty_struct *tty);
474static int stl_writeroom(struct tty_struct *tty);
475static int stl_charsinbuffer(struct tty_struct *tty);
476static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
477static void stl_settermios(struct tty_struct *tty, struct termios *old);
478static void stl_throttle(struct tty_struct *tty);
479static void stl_unthrottle(struct tty_struct *tty);
480static void stl_stop(struct tty_struct *tty);
481static void stl_start(struct tty_struct *tty);
482static void stl_flushbuffer(struct tty_struct *tty);
483static void stl_breakctl(struct tty_struct *tty, int state);
484static void stl_waituntilsent(struct tty_struct *tty, int timeout);
485static void stl_sendxchar(struct tty_struct *tty, char ch);
486static void stl_hangup(struct tty_struct *tty);
487static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
488static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
489static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
490
491static int stl_brdinit(stlbrd_t *brdp);
492static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
493static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
494static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
495static int stl_getbrdstats(combrd_t __user *bp);
496static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
497static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
498static int stl_getportstruct(stlport_t __user *arg);
499static int stl_getbrdstruct(stlbrd_t __user *arg);
500static int stl_waitcarrier(stlport_t *portp, struct file *filp);
501static int stl_eiointr(stlbrd_t *brdp);
502static int stl_echatintr(stlbrd_t *brdp);
503static int stl_echmcaintr(stlbrd_t *brdp);
504static int stl_echpciintr(stlbrd_t *brdp);
505static int stl_echpci64intr(stlbrd_t *brdp);
506static void stl_offintr(void *private);
1da177e4
LT
507static stlbrd_t *stl_allocbrd(void);
508static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
509
510static inline int stl_initbrds(void);
511static inline int stl_initeio(stlbrd_t *brdp);
512static inline int stl_initech(stlbrd_t *brdp);
513static inline int stl_getbrdnr(void);
514
515#ifdef CONFIG_PCI
516static inline int stl_findpcibrds(void);
517static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
518#endif
519
520/*
521 * CD1400 uart specific handling functions.
522 */
523static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
524static int stl_cd1400getreg(stlport_t *portp, int regnr);
525static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
526static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
527static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
528static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
529static int stl_cd1400getsignals(stlport_t *portp);
530static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
531static void stl_cd1400ccrwait(stlport_t *portp);
532static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
533static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
534static void stl_cd1400disableintrs(stlport_t *portp);
535static void stl_cd1400sendbreak(stlport_t *portp, int len);
536static void stl_cd1400flowctrl(stlport_t *portp, int state);
537static void stl_cd1400sendflow(stlport_t *portp, int state);
538static void stl_cd1400flush(stlport_t *portp);
539static int stl_cd1400datastate(stlport_t *portp);
540static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
541static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
542static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
543static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
544static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
545
546static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
547
548/*
549 * SC26198 uart specific handling functions.
550 */
551static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
552static int stl_sc26198getreg(stlport_t *portp, int regnr);
553static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
554static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
555static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
556static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
557static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
558static int stl_sc26198getsignals(stlport_t *portp);
559static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
560static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
561static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
562static void stl_sc26198disableintrs(stlport_t *portp);
563static void stl_sc26198sendbreak(stlport_t *portp, int len);
564static void stl_sc26198flowctrl(stlport_t *portp, int state);
565static void stl_sc26198sendflow(stlport_t *portp, int state);
566static void stl_sc26198flush(stlport_t *portp);
567static int stl_sc26198datastate(stlport_t *portp);
568static void stl_sc26198wait(stlport_t *portp);
569static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
570static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
571static void stl_sc26198txisr(stlport_t *port);
572static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
573static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
574static void stl_sc26198rxbadchars(stlport_t *portp);
575static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
576
577/*****************************************************************************/
578
579/*
580 * Generic UART support structure.
581 */
582typedef struct uart {
583 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
584 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
585 void (*setport)(stlport_t *portp, struct termios *tiosp);
586 int (*getsignals)(stlport_t *portp);
587 void (*setsignals)(stlport_t *portp, int dtr, int rts);
588 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
589 void (*startrxtx)(stlport_t *portp, int rx, int tx);
590 void (*disableintrs)(stlport_t *portp);
591 void (*sendbreak)(stlport_t *portp, int len);
592 void (*flowctrl)(stlport_t *portp, int state);
593 void (*sendflow)(stlport_t *portp, int state);
594 void (*flush)(stlport_t *portp);
595 int (*datastate)(stlport_t *portp);
596 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
597} uart_t;
598
599/*
600 * Define some macros to make calling these functions nice and clean.
601 */
602#define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
603#define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
604#define stl_setport (* ((uart_t *) portp->uartp)->setport)
605#define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
606#define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
607#define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
608#define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
609#define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
610#define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
611#define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
612#define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
613#define stl_flush (* ((uart_t *) portp->uartp)->flush)
614#define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
615
616/*****************************************************************************/
617
618/*
619 * CD1400 UART specific data initialization.
620 */
621static uart_t stl_cd1400uart = {
622 stl_cd1400panelinit,
623 stl_cd1400portinit,
624 stl_cd1400setport,
625 stl_cd1400getsignals,
626 stl_cd1400setsignals,
627 stl_cd1400enablerxtx,
628 stl_cd1400startrxtx,
629 stl_cd1400disableintrs,
630 stl_cd1400sendbreak,
631 stl_cd1400flowctrl,
632 stl_cd1400sendflow,
633 stl_cd1400flush,
634 stl_cd1400datastate,
635 stl_cd1400eiointr
636};
637
638/*
639 * Define the offsets within the register bank of a cd1400 based panel.
640 * These io address offsets are common to the EasyIO board as well.
641 */
642#define EREG_ADDR 0
643#define EREG_DATA 4
644#define EREG_RXACK 5
645#define EREG_TXACK 6
646#define EREG_MDACK 7
647
648#define EREG_BANKSIZE 8
649
650#define CD1400_CLK 25000000
651#define CD1400_CLK8M 20000000
652
653/*
654 * Define the cd1400 baud rate clocks. These are used when calculating
655 * what clock and divisor to use for the required baud rate. Also
656 * define the maximum baud rate allowed, and the default base baud.
657 */
658static int stl_cd1400clkdivs[] = {
659 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
660};
661
662/*****************************************************************************/
663
664/*
665 * SC26198 UART specific data initization.
666 */
667static uart_t stl_sc26198uart = {
668 stl_sc26198panelinit,
669 stl_sc26198portinit,
670 stl_sc26198setport,
671 stl_sc26198getsignals,
672 stl_sc26198setsignals,
673 stl_sc26198enablerxtx,
674 stl_sc26198startrxtx,
675 stl_sc26198disableintrs,
676 stl_sc26198sendbreak,
677 stl_sc26198flowctrl,
678 stl_sc26198sendflow,
679 stl_sc26198flush,
680 stl_sc26198datastate,
681 stl_sc26198intr
682};
683
684/*
685 * Define the offsets within the register bank of a sc26198 based panel.
686 */
687#define XP_DATA 0
688#define XP_ADDR 1
689#define XP_MODID 2
690#define XP_STATUS 2
691#define XP_IACK 3
692
693#define XP_BANKSIZE 4
694
695/*
696 * Define the sc26198 baud rate table. Offsets within the table
697 * represent the actual baud rate selector of sc26198 registers.
698 */
699static unsigned int sc26198_baudtable[] = {
700 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
701 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
702 230400, 460800, 921600
703};
704
fe971071 705#define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
1da177e4
LT
706
707/*****************************************************************************/
708
709/*
710 * Define the driver info for a user level control device. Used mainly
711 * to get at port stats - only not using the port device itself.
712 */
713static struct file_operations stl_fsiomem = {
714 .owner = THIS_MODULE,
715 .ioctl = stl_memioctl,
716};
717
718/*****************************************************************************/
719
ca8eca68 720static struct class *stallion_class;
1da177e4
LT
721
722/*
723 * Loadable module initialization stuff.
724 */
725
726static int __init stallion_module_init(void)
727{
728 unsigned long flags;
729
730#ifdef DEBUG
731 printk("init_module()\n");
732#endif
733
734 save_flags(flags);
735 cli();
736 stl_init();
737 restore_flags(flags);
738
014c2544 739 return 0;
1da177e4
LT
740}
741
742/*****************************************************************************/
743
744static void __exit stallion_module_exit(void)
745{
746 stlbrd_t *brdp;
747 stlpanel_t *panelp;
748 stlport_t *portp;
749 unsigned long flags;
750 int i, j, k;
751
752#ifdef DEBUG
753 printk("cleanup_module()\n");
754#endif
755
756 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
757 stl_drvversion);
758
759 save_flags(flags);
760 cli();
761
762/*
763 * Free up all allocated resources used by the ports. This includes
764 * memory and interrupts. As part of this process we will also do
765 * a hangup on every open port - to try to flush out any processes
766 * hanging onto ports.
767 */
768 i = tty_unregister_driver(stl_serial);
769 put_tty_driver(stl_serial);
770 if (i) {
771 printk("STALLION: failed to un-register tty driver, "
772 "errno=%d\n", -i);
773 restore_flags(flags);
774 return;
775 }
776 for (i = 0; i < 4; i++) {
777 devfs_remove("staliomem/%d", i);
ca8eca68 778 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
1da177e4
LT
779 }
780 devfs_remove("staliomem");
781 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
782 printk("STALLION: failed to un-register serial memory device, "
783 "errno=%d\n", -i);
ca8eca68 784 class_destroy(stallion_class);
1da177e4 785
735d5661 786 kfree(stl_tmpwritebuf);
1da177e4
LT
787
788 for (i = 0; (i < stl_nrbrds); i++) {
789 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
790 continue;
791
792 free_irq(brdp->irq, brdp);
793
794 for (j = 0; (j < STL_MAXPANELS); j++) {
795 panelp = brdp->panels[j];
796 if (panelp == (stlpanel_t *) NULL)
797 continue;
798 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
799 portp = panelp->ports[k];
800 if (portp == (stlport_t *) NULL)
801 continue;
802 if (portp->tty != (struct tty_struct *) NULL)
803 stl_hangup(portp->tty);
735d5661 804 kfree(portp->tx.buf);
1da177e4
LT
805 kfree(portp);
806 }
807 kfree(panelp);
808 }
809
810 release_region(brdp->ioaddr1, brdp->iosize1);
811 if (brdp->iosize2 > 0)
812 release_region(brdp->ioaddr2, brdp->iosize2);
813
814 kfree(brdp);
815 stl_brds[i] = (stlbrd_t *) NULL;
816 }
817
818 restore_flags(flags);
819}
820
821module_init(stallion_module_init);
822module_exit(stallion_module_exit);
823
824/*****************************************************************************/
825
826/*
827 * Check for any arguments passed in on the module load command line.
828 */
829
830static void stl_argbrds(void)
831{
832 stlconf_t conf;
833 stlbrd_t *brdp;
834 int i;
835
836#ifdef DEBUG
837 printk("stl_argbrds()\n");
838#endif
839
840 for (i = stl_nrbrds; (i < stl_nargs); i++) {
841 memset(&conf, 0, sizeof(conf));
842 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
843 continue;
844 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
845 continue;
846 stl_nrbrds = i + 1;
847 brdp->brdnr = i;
848 brdp->brdtype = conf.brdtype;
849 brdp->ioaddr1 = conf.ioaddr1;
850 brdp->ioaddr2 = conf.ioaddr2;
851 brdp->irq = conf.irq;
852 brdp->irqtype = conf.irqtype;
853 stl_brdinit(brdp);
854 }
855}
856
857/*****************************************************************************/
858
859/*
860 * Convert an ascii string number into an unsigned long.
861 */
862
863static unsigned long stl_atol(char *str)
864{
865 unsigned long val;
866 int base, c;
867 char *sp;
868
869 val = 0;
870 sp = str;
871 if ((*sp == '0') && (*(sp+1) == 'x')) {
872 base = 16;
873 sp += 2;
874 } else if (*sp == '0') {
875 base = 8;
876 sp++;
877 } else {
878 base = 10;
879 }
880
881 for (; (*sp != 0); sp++) {
882 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
883 if ((c < 0) || (c >= base)) {
884 printk("STALLION: invalid argument %s\n", str);
885 val = 0;
886 break;
887 }
888 val = (val * base) + c;
889 }
014c2544 890 return val;
1da177e4
LT
891}
892
893/*****************************************************************************/
894
895/*
896 * Parse the supplied argument string, into the board conf struct.
897 */
898
899static int stl_parsebrd(stlconf_t *confp, char **argp)
900{
901 char *sp;
fe971071 902 int i;
1da177e4
LT
903
904#ifdef DEBUG
905 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
906#endif
907
908 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
014c2544 909 return 0;
1da177e4
LT
910
911 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
912 *sp = TOLOWER(*sp);
913
fe971071 914 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
1da177e4
LT
915 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
916 break;
917 }
fe971071 918 if (i == ARRAY_SIZE(stl_brdstr)) {
1da177e4 919 printk("STALLION: unknown board name, %s?\n", argp[0]);
fe971071 920 return 0;
1da177e4
LT
921 }
922
923 confp->brdtype = stl_brdstr[i].type;
924
925 i = 1;
926 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
927 confp->ioaddr1 = stl_atol(argp[i]);
928 i++;
929 if (confp->brdtype == BRD_ECH) {
930 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
931 confp->ioaddr2 = stl_atol(argp[i]);
932 i++;
933 }
934 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
935 confp->irq = stl_atol(argp[i]);
014c2544 936 return 1;
1da177e4
LT
937}
938
939/*****************************************************************************/
940
1da177e4
LT
941/*
942 * Allocate a new board structure. Fill out the basic info in it.
943 */
944
945static stlbrd_t *stl_allocbrd(void)
946{
947 stlbrd_t *brdp;
948
b0b4ed72
TK
949 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
950 if (!brdp) {
1da177e4
LT
951 printk("STALLION: failed to allocate memory (size=%d)\n",
952 sizeof(stlbrd_t));
b0b4ed72 953 return NULL;
1da177e4
LT
954 }
955
1da177e4 956 brdp->magic = STL_BOARDMAGIC;
014c2544 957 return brdp;
1da177e4
LT
958}
959
960/*****************************************************************************/
961
962static int stl_open(struct tty_struct *tty, struct file *filp)
963{
964 stlport_t *portp;
965 stlbrd_t *brdp;
966 unsigned int minordev;
967 int brdnr, panelnr, portnr, rc;
968
969#ifdef DEBUG
970 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
971 (int) filp, tty->name);
972#endif
973
974 minordev = tty->index;
975 brdnr = MINOR2BRD(minordev);
976 if (brdnr >= stl_nrbrds)
014c2544 977 return -ENODEV;
1da177e4
LT
978 brdp = stl_brds[brdnr];
979 if (brdp == (stlbrd_t *) NULL)
014c2544 980 return -ENODEV;
1da177e4
LT
981 minordev = MINOR2PORT(minordev);
982 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
983 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
984 break;
985 if (minordev < brdp->panels[panelnr]->nrports) {
986 portnr = minordev;
987 break;
988 }
989 minordev -= brdp->panels[panelnr]->nrports;
990 }
991 if (portnr < 0)
014c2544 992 return -ENODEV;
1da177e4
LT
993
994 portp = brdp->panels[panelnr]->ports[portnr];
995 if (portp == (stlport_t *) NULL)
014c2544 996 return -ENODEV;
1da177e4
LT
997
998/*
999 * On the first open of the device setup the port hardware, and
1000 * initialize the per port data structure.
1001 */
1002 portp->tty = tty;
1003 tty->driver_data = portp;
1004 portp->refcount++;
1005
1006 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
b0b4ed72
TK
1007 if (!portp->tx.buf) {
1008 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
1009 if (!portp->tx.buf)
014c2544 1010 return -ENOMEM;
1da177e4
LT
1011 portp->tx.head = portp->tx.buf;
1012 portp->tx.tail = portp->tx.buf;
1013 }
1014 stl_setport(portp, tty->termios);
1015 portp->sigs = stl_getsignals(portp);
1016 stl_setsignals(portp, 1, 1);
1017 stl_enablerxtx(portp, 1, 1);
1018 stl_startrxtx(portp, 1, 0);
1019 clear_bit(TTY_IO_ERROR, &tty->flags);
1020 portp->flags |= ASYNC_INITIALIZED;
1021 }
1022
1023/*
1024 * Check if this port is in the middle of closing. If so then wait
1025 * until it is closed then return error status, based on flag settings.
1026 * The sleep here does not need interrupt protection since the wakeup
1027 * for it is done with the same context.
1028 */
1029 if (portp->flags & ASYNC_CLOSING) {
1030 interruptible_sleep_on(&portp->close_wait);
1031 if (portp->flags & ASYNC_HUP_NOTIFY)
014c2544
JJ
1032 return -EAGAIN;
1033 return -ERESTARTSYS;
1da177e4
LT
1034 }
1035
1036/*
1037 * Based on type of open being done check if it can overlap with any
1038 * previous opens still in effect. If we are a normal serial device
1039 * then also we might have to wait for carrier.
1040 */
1041 if (!(filp->f_flags & O_NONBLOCK)) {
1042 if ((rc = stl_waitcarrier(portp, filp)) != 0)
014c2544 1043 return rc;
1da177e4
LT
1044 }
1045 portp->flags |= ASYNC_NORMAL_ACTIVE;
1046
014c2544 1047 return 0;
1da177e4
LT
1048}
1049
1050/*****************************************************************************/
1051
1052/*
1053 * Possibly need to wait for carrier (DCD signal) to come high. Say
1054 * maybe because if we are clocal then we don't need to wait...
1055 */
1056
1057static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1058{
1059 unsigned long flags;
1060 int rc, doclocal;
1061
1062#ifdef DEBUG
1063 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1064#endif
1065
1066 rc = 0;
1067 doclocal = 0;
1068
1069 if (portp->tty->termios->c_cflag & CLOCAL)
1070 doclocal++;
1071
1072 save_flags(flags);
1073 cli();
1074 portp->openwaitcnt++;
1075 if (! tty_hung_up_p(filp))
1076 portp->refcount--;
1077
1078 for (;;) {
1079 stl_setsignals(portp, 1, 1);
1080 if (tty_hung_up_p(filp) ||
1081 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1082 if (portp->flags & ASYNC_HUP_NOTIFY)
1083 rc = -EBUSY;
1084 else
1085 rc = -ERESTARTSYS;
1086 break;
1087 }
1088 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1089 (doclocal || (portp->sigs & TIOCM_CD))) {
1090 break;
1091 }
1092 if (signal_pending(current)) {
1093 rc = -ERESTARTSYS;
1094 break;
1095 }
1096 interruptible_sleep_on(&portp->open_wait);
1097 }
1098
1099 if (! tty_hung_up_p(filp))
1100 portp->refcount++;
1101 portp->openwaitcnt--;
1102 restore_flags(flags);
1103
014c2544 1104 return rc;
1da177e4
LT
1105}
1106
1107/*****************************************************************************/
1108
1109static void stl_close(struct tty_struct *tty, struct file *filp)
1110{
1111 stlport_t *portp;
1112 unsigned long flags;
1113
1114#ifdef DEBUG
1115 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1116#endif
1117
1118 portp = tty->driver_data;
1119 if (portp == (stlport_t *) NULL)
1120 return;
1121
1122 save_flags(flags);
1123 cli();
1124 if (tty_hung_up_p(filp)) {
1125 restore_flags(flags);
1126 return;
1127 }
1128 if ((tty->count == 1) && (portp->refcount != 1))
1129 portp->refcount = 1;
1130 if (portp->refcount-- > 1) {
1131 restore_flags(flags);
1132 return;
1133 }
1134
1135 portp->refcount = 0;
1136 portp->flags |= ASYNC_CLOSING;
1137
1138/*
1139 * May want to wait for any data to drain before closing. The BUSY
1140 * flag keeps track of whether we are still sending or not - it is
1141 * very accurate for the cd1400, not quite so for the sc26198.
1142 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1143 */
1144 tty->closing = 1;
1145 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1146 tty_wait_until_sent(tty, portp->closing_wait);
1147 stl_waituntilsent(tty, (HZ / 2));
1148
1149 portp->flags &= ~ASYNC_INITIALIZED;
1150 stl_disableintrs(portp);
1151 if (tty->termios->c_cflag & HUPCL)
1152 stl_setsignals(portp, 0, 0);
1153 stl_enablerxtx(portp, 0, 0);
1154 stl_flushbuffer(tty);
1155 portp->istate = 0;
1156 if (portp->tx.buf != (char *) NULL) {
1157 kfree(portp->tx.buf);
1158 portp->tx.buf = (char *) NULL;
1159 portp->tx.head = (char *) NULL;
1160 portp->tx.tail = (char *) NULL;
1161 }
1162 set_bit(TTY_IO_ERROR, &tty->flags);
1163 tty_ldisc_flush(tty);
1164
1165 tty->closing = 0;
1166 portp->tty = (struct tty_struct *) NULL;
1167
1168 if (portp->openwaitcnt) {
1169 if (portp->close_delay)
1170 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1171 wake_up_interruptible(&portp->open_wait);
1172 }
1173
1174 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1175 wake_up_interruptible(&portp->close_wait);
1176 restore_flags(flags);
1177}
1178
1179/*****************************************************************************/
1180
1181/*
1182 * Write routine. Take data and stuff it in to the TX ring queue.
1183 * If transmit interrupts are not running then start them.
1184 */
1185
1186static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1187{
1188 stlport_t *portp;
1189 unsigned int len, stlen;
1190 unsigned char *chbuf;
1191 char *head, *tail;
1192
1193#ifdef DEBUG
1194 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1195 (int) tty, (int) buf, count);
1196#endif
1197
1198 if ((tty == (struct tty_struct *) NULL) ||
1199 (stl_tmpwritebuf == (char *) NULL))
014c2544 1200 return 0;
1da177e4
LT
1201 portp = tty->driver_data;
1202 if (portp == (stlport_t *) NULL)
014c2544 1203 return 0;
1da177e4 1204 if (portp->tx.buf == (char *) NULL)
014c2544 1205 return 0;
1da177e4
LT
1206
1207/*
1208 * If copying direct from user space we must cater for page faults,
1209 * causing us to "sleep" here for a while. To handle this copy in all
1210 * the data we need now, into a local buffer. Then when we got it all
1211 * copy it into the TX buffer.
1212 */
1213 chbuf = (unsigned char *) buf;
1214
1215 head = portp->tx.head;
1216 tail = portp->tx.tail;
1217 if (head >= tail) {
1218 len = STL_TXBUFSIZE - (head - tail) - 1;
1219 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1220 } else {
1221 len = tail - head - 1;
1222 stlen = len;
1223 }
1224
1225 len = MIN(len, count);
1226 count = 0;
1227 while (len > 0) {
1228 stlen = MIN(len, stlen);
1229 memcpy(head, chbuf, stlen);
1230 len -= stlen;
1231 chbuf += stlen;
1232 count += stlen;
1233 head += stlen;
1234 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1235 head = portp->tx.buf;
1236 stlen = tail - head;
1237 }
1238 }
1239 portp->tx.head = head;
1240
1241 clear_bit(ASYI_TXLOW, &portp->istate);
1242 stl_startrxtx(portp, -1, 1);
1243
014c2544 1244 return count;
1da177e4
LT
1245}
1246
1247/*****************************************************************************/
1248
1249static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1250{
1251 stlport_t *portp;
1252 unsigned int len;
1253 char *head, *tail;
1254
1255#ifdef DEBUG
1256 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1257#endif
1258
1259 if (tty == (struct tty_struct *) NULL)
1260 return;
1261 portp = tty->driver_data;
1262 if (portp == (stlport_t *) NULL)
1263 return;
1264 if (portp->tx.buf == (char *) NULL)
1265 return;
1266
1267 head = portp->tx.head;
1268 tail = portp->tx.tail;
1269
1270 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1271 len--;
1272
1273 if (len > 0) {
1274 *head++ = ch;
1275 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1276 head = portp->tx.buf;
1277 }
1278 portp->tx.head = head;
1279}
1280
1281/*****************************************************************************/
1282
1283/*
1284 * If there are any characters in the buffer then make sure that TX
1285 * interrupts are on and get'em out. Normally used after the putchar
1286 * routine has been called.
1287 */
1288
1289static void stl_flushchars(struct tty_struct *tty)
1290{
1291 stlport_t *portp;
1292
1293#ifdef DEBUG
1294 printk("stl_flushchars(tty=%x)\n", (int) tty);
1295#endif
1296
1297 if (tty == (struct tty_struct *) NULL)
1298 return;
1299 portp = tty->driver_data;
1300 if (portp == (stlport_t *) NULL)
1301 return;
1302 if (portp->tx.buf == (char *) NULL)
1303 return;
1304
1305#if 0
1306 if (tty->stopped || tty->hw_stopped ||
1307 (portp->tx.head == portp->tx.tail))
1308 return;
1309#endif
1310 stl_startrxtx(portp, -1, 1);
1311}
1312
1313/*****************************************************************************/
1314
1315static int stl_writeroom(struct tty_struct *tty)
1316{
1317 stlport_t *portp;
1318 char *head, *tail;
1319
1320#ifdef DEBUG
1321 printk("stl_writeroom(tty=%x)\n", (int) tty);
1322#endif
1323
1324 if (tty == (struct tty_struct *) NULL)
014c2544 1325 return 0;
1da177e4
LT
1326 portp = tty->driver_data;
1327 if (portp == (stlport_t *) NULL)
014c2544 1328 return 0;
1da177e4 1329 if (portp->tx.buf == (char *) NULL)
014c2544 1330 return 0;
1da177e4
LT
1331
1332 head = portp->tx.head;
1333 tail = portp->tx.tail;
014c2544 1334 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1da177e4
LT
1335}
1336
1337/*****************************************************************************/
1338
1339/*
1340 * Return number of chars in the TX buffer. Normally we would just
1341 * calculate the number of chars in the buffer and return that, but if
1342 * the buffer is empty and TX interrupts are still on then we return
1343 * that the buffer still has 1 char in it. This way whoever called us
1344 * will not think that ALL chars have drained - since the UART still
1345 * must have some chars in it (we are busy after all).
1346 */
1347
1348static int stl_charsinbuffer(struct tty_struct *tty)
1349{
1350 stlport_t *portp;
1351 unsigned int size;
1352 char *head, *tail;
1353
1354#ifdef DEBUG
1355 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1356#endif
1357
1358 if (tty == (struct tty_struct *) NULL)
014c2544 1359 return 0;
1da177e4
LT
1360 portp = tty->driver_data;
1361 if (portp == (stlport_t *) NULL)
014c2544 1362 return 0;
1da177e4 1363 if (portp->tx.buf == (char *) NULL)
014c2544 1364 return 0;
1da177e4
LT
1365
1366 head = portp->tx.head;
1367 tail = portp->tx.tail;
1368 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1369 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1370 size = 1;
014c2544 1371 return size;
1da177e4
LT
1372}
1373
1374/*****************************************************************************/
1375
1376/*
1377 * Generate the serial struct info.
1378 */
1379
1380static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1381{
1382 struct serial_struct sio;
1383 stlbrd_t *brdp;
1384
1385#ifdef DEBUG
1386 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1387#endif
1388
1389 memset(&sio, 0, sizeof(struct serial_struct));
1390 sio.line = portp->portnr;
1391 sio.port = portp->ioaddr;
1392 sio.flags = portp->flags;
1393 sio.baud_base = portp->baud_base;
1394 sio.close_delay = portp->close_delay;
1395 sio.closing_wait = portp->closing_wait;
1396 sio.custom_divisor = portp->custom_divisor;
1397 sio.hub6 = 0;
1398 if (portp->uartp == &stl_cd1400uart) {
1399 sio.type = PORT_CIRRUS;
1400 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1401 } else {
1402 sio.type = PORT_UNKNOWN;
1403 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1404 }
1405
1406 brdp = stl_brds[portp->brdnr];
1407 if (brdp != (stlbrd_t *) NULL)
1408 sio.irq = brdp->irq;
1409
1410 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1411}
1412
1413/*****************************************************************************/
1414
1415/*
1416 * Set port according to the serial struct info.
1417 * At this point we do not do any auto-configure stuff, so we will
1418 * just quietly ignore any requests to change irq, etc.
1419 */
1420
1421static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
1422{
1423 struct serial_struct sio;
1424
1425#ifdef DEBUG
1426 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1427#endif
1428
1429 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1430 return -EFAULT;
1431 if (!capable(CAP_SYS_ADMIN)) {
1432 if ((sio.baud_base != portp->baud_base) ||
1433 (sio.close_delay != portp->close_delay) ||
1434 ((sio.flags & ~ASYNC_USR_MASK) !=
1435 (portp->flags & ~ASYNC_USR_MASK)))
014c2544 1436 return -EPERM;
1da177e4
LT
1437 }
1438
1439 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1440 (sio.flags & ASYNC_USR_MASK);
1441 portp->baud_base = sio.baud_base;
1442 portp->close_delay = sio.close_delay;
1443 portp->closing_wait = sio.closing_wait;
1444 portp->custom_divisor = sio.custom_divisor;
1445 stl_setport(portp, portp->tty->termios);
014c2544 1446 return 0;
1da177e4
LT
1447}
1448
1449/*****************************************************************************/
1450
1451static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1452{
1453 stlport_t *portp;
1454
1455 if (tty == (struct tty_struct *) NULL)
014c2544 1456 return -ENODEV;
1da177e4
LT
1457 portp = tty->driver_data;
1458 if (portp == (stlport_t *) NULL)
014c2544 1459 return -ENODEV;
1da177e4 1460 if (tty->flags & (1 << TTY_IO_ERROR))
014c2544 1461 return -EIO;
1da177e4
LT
1462
1463 return stl_getsignals(portp);
1464}
1465
1466static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1467 unsigned int set, unsigned int clear)
1468{
1469 stlport_t *portp;
1470 int rts = -1, dtr = -1;
1471
1472 if (tty == (struct tty_struct *) NULL)
014c2544 1473 return -ENODEV;
1da177e4
LT
1474 portp = tty->driver_data;
1475 if (portp == (stlport_t *) NULL)
014c2544 1476 return -ENODEV;
1da177e4 1477 if (tty->flags & (1 << TTY_IO_ERROR))
014c2544 1478 return -EIO;
1da177e4
LT
1479
1480 if (set & TIOCM_RTS)
1481 rts = 1;
1482 if (set & TIOCM_DTR)
1483 dtr = 1;
1484 if (clear & TIOCM_RTS)
1485 rts = 0;
1486 if (clear & TIOCM_DTR)
1487 dtr = 0;
1488
1489 stl_setsignals(portp, dtr, rts);
1490 return 0;
1491}
1492
1493static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1494{
1495 stlport_t *portp;
1496 unsigned int ival;
1497 int rc;
1498 void __user *argp = (void __user *)arg;
1499
1500#ifdef DEBUG
1501 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1502 (int) tty, (int) file, cmd, (int) arg);
1503#endif
1504
1505 if (tty == (struct tty_struct *) NULL)
014c2544 1506 return -ENODEV;
1da177e4
LT
1507 portp = tty->driver_data;
1508 if (portp == (stlport_t *) NULL)
014c2544 1509 return -ENODEV;
1da177e4
LT
1510
1511 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1512 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1513 if (tty->flags & (1 << TTY_IO_ERROR))
014c2544 1514 return -EIO;
1da177e4
LT
1515 }
1516
1517 rc = 0;
1518
1519 switch (cmd) {
1520 case TIOCGSOFTCAR:
1521 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1522 (unsigned __user *) argp);
1523 break;
1524 case TIOCSSOFTCAR:
1525 if (get_user(ival, (unsigned int __user *) arg))
1526 return -EFAULT;
1527 tty->termios->c_cflag =
1528 (tty->termios->c_cflag & ~CLOCAL) |
1529 (ival ? CLOCAL : 0);
1530 break;
1531 case TIOCGSERIAL:
1532 rc = stl_getserial(portp, argp);
1533 break;
1534 case TIOCSSERIAL:
1535 rc = stl_setserial(portp, argp);
1536 break;
1537 case COM_GETPORTSTATS:
1538 rc = stl_getportstats(portp, argp);
1539 break;
1540 case COM_CLRPORTSTATS:
1541 rc = stl_clrportstats(portp, argp);
1542 break;
1543 case TIOCSERCONFIG:
1544 case TIOCSERGWILD:
1545 case TIOCSERSWILD:
1546 case TIOCSERGETLSR:
1547 case TIOCSERGSTRUCT:
1548 case TIOCSERGETMULTI:
1549 case TIOCSERSETMULTI:
1550 default:
1551 rc = -ENOIOCTLCMD;
1552 break;
1553 }
1554
014c2544 1555 return rc;
1da177e4
LT
1556}
1557
1558/*****************************************************************************/
1559
1560static void stl_settermios(struct tty_struct *tty, struct termios *old)
1561{
1562 stlport_t *portp;
1563 struct termios *tiosp;
1564
1565#ifdef DEBUG
1566 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1567#endif
1568
1569 if (tty == (struct tty_struct *) NULL)
1570 return;
1571 portp = tty->driver_data;
1572 if (portp == (stlport_t *) NULL)
1573 return;
1574
1575 tiosp = tty->termios;
1576 if ((tiosp->c_cflag == old->c_cflag) &&
1577 (tiosp->c_iflag == old->c_iflag))
1578 return;
1579
1580 stl_setport(portp, tiosp);
1581 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1582 -1);
1583 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1584 tty->hw_stopped = 0;
1585 stl_start(tty);
1586 }
1587 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1588 wake_up_interruptible(&portp->open_wait);
1589}
1590
1591/*****************************************************************************/
1592
1593/*
1594 * Attempt to flow control who ever is sending us data. Based on termios
1595 * settings use software or/and hardware flow control.
1596 */
1597
1598static void stl_throttle(struct tty_struct *tty)
1599{
1600 stlport_t *portp;
1601
1602#ifdef DEBUG
1603 printk("stl_throttle(tty=%x)\n", (int) tty);
1604#endif
1605
1606 if (tty == (struct tty_struct *) NULL)
1607 return;
1608 portp = tty->driver_data;
1609 if (portp == (stlport_t *) NULL)
1610 return;
1611 stl_flowctrl(portp, 0);
1612}
1613
1614/*****************************************************************************/
1615
1616/*
1617 * Unflow control the device sending us data...
1618 */
1619
1620static void stl_unthrottle(struct tty_struct *tty)
1621{
1622 stlport_t *portp;
1623
1624#ifdef DEBUG
1625 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1626#endif
1627
1628 if (tty == (struct tty_struct *) NULL)
1629 return;
1630 portp = tty->driver_data;
1631 if (portp == (stlport_t *) NULL)
1632 return;
1633 stl_flowctrl(portp, 1);
1634}
1635
1636/*****************************************************************************/
1637
1638/*
1639 * Stop the transmitter. Basically to do this we will just turn TX
1640 * interrupts off.
1641 */
1642
1643static void stl_stop(struct tty_struct *tty)
1644{
1645 stlport_t *portp;
1646
1647#ifdef DEBUG
1648 printk("stl_stop(tty=%x)\n", (int) tty);
1649#endif
1650
1651 if (tty == (struct tty_struct *) NULL)
1652 return;
1653 portp = tty->driver_data;
1654 if (portp == (stlport_t *) NULL)
1655 return;
1656 stl_startrxtx(portp, -1, 0);
1657}
1658
1659/*****************************************************************************/
1660
1661/*
1662 * Start the transmitter again. Just turn TX interrupts back on.
1663 */
1664
1665static void stl_start(struct tty_struct *tty)
1666{
1667 stlport_t *portp;
1668
1669#ifdef DEBUG
1670 printk("stl_start(tty=%x)\n", (int) tty);
1671#endif
1672
1673 if (tty == (struct tty_struct *) NULL)
1674 return;
1675 portp = tty->driver_data;
1676 if (portp == (stlport_t *) NULL)
1677 return;
1678 stl_startrxtx(portp, -1, 1);
1679}
1680
1681/*****************************************************************************/
1682
1683/*
1684 * Hangup this port. This is pretty much like closing the port, only
1685 * a little more brutal. No waiting for data to drain. Shutdown the
1686 * port and maybe drop signals.
1687 */
1688
1689static void stl_hangup(struct tty_struct *tty)
1690{
1691 stlport_t *portp;
1692
1693#ifdef DEBUG
1694 printk("stl_hangup(tty=%x)\n", (int) tty);
1695#endif
1696
1697 if (tty == (struct tty_struct *) NULL)
1698 return;
1699 portp = tty->driver_data;
1700 if (portp == (stlport_t *) NULL)
1701 return;
1702
1703 portp->flags &= ~ASYNC_INITIALIZED;
1704 stl_disableintrs(portp);
1705 if (tty->termios->c_cflag & HUPCL)
1706 stl_setsignals(portp, 0, 0);
1707 stl_enablerxtx(portp, 0, 0);
1708 stl_flushbuffer(tty);
1709 portp->istate = 0;
1710 set_bit(TTY_IO_ERROR, &tty->flags);
1711 if (portp->tx.buf != (char *) NULL) {
1712 kfree(portp->tx.buf);
1713 portp->tx.buf = (char *) NULL;
1714 portp->tx.head = (char *) NULL;
1715 portp->tx.tail = (char *) NULL;
1716 }
1717 portp->tty = (struct tty_struct *) NULL;
1718 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1719 portp->refcount = 0;
1720 wake_up_interruptible(&portp->open_wait);
1721}
1722
1723/*****************************************************************************/
1724
1725static void stl_flushbuffer(struct tty_struct *tty)
1726{
1727 stlport_t *portp;
1728
1729#ifdef DEBUG
1730 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1731#endif
1732
1733 if (tty == (struct tty_struct *) NULL)
1734 return;
1735 portp = tty->driver_data;
1736 if (portp == (stlport_t *) NULL)
1737 return;
1738
1739 stl_flush(portp);
1740 tty_wakeup(tty);
1741}
1742
1743/*****************************************************************************/
1744
1745static void stl_breakctl(struct tty_struct *tty, int state)
1746{
1747 stlport_t *portp;
1748
1749#ifdef DEBUG
1750 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1751#endif
1752
1753 if (tty == (struct tty_struct *) NULL)
1754 return;
1755 portp = tty->driver_data;
1756 if (portp == (stlport_t *) NULL)
1757 return;
1758
1759 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1760}
1761
1762/*****************************************************************************/
1763
1764static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1765{
1766 stlport_t *portp;
1767 unsigned long tend;
1768
1769#ifdef DEBUG
1770 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1771#endif
1772
1773 if (tty == (struct tty_struct *) NULL)
1774 return;
1775 portp = tty->driver_data;
1776 if (portp == (stlport_t *) NULL)
1777 return;
1778
1779 if (timeout == 0)
1780 timeout = HZ;
1781 tend = jiffies + timeout;
1782
1783 while (stl_datastate(portp)) {
1784 if (signal_pending(current))
1785 break;
1786 msleep_interruptible(20);
1787 if (time_after_eq(jiffies, tend))
1788 break;
1789 }
1790}
1791
1792/*****************************************************************************/
1793
1794static void stl_sendxchar(struct tty_struct *tty, char ch)
1795{
1796 stlport_t *portp;
1797
1798#ifdef DEBUG
1799 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1800#endif
1801
1802 if (tty == (struct tty_struct *) NULL)
1803 return;
1804 portp = tty->driver_data;
1805 if (portp == (stlport_t *) NULL)
1806 return;
1807
1808 if (ch == STOP_CHAR(tty))
1809 stl_sendflow(portp, 0);
1810 else if (ch == START_CHAR(tty))
1811 stl_sendflow(portp, 1);
1812 else
1813 stl_putchar(tty, ch);
1814}
1815
1816/*****************************************************************************/
1817
1818#define MAXLINE 80
1819
1820/*
1821 * Format info for a specified port. The line is deliberately limited
1822 * to 80 characters. (If it is too long it will be truncated, if too
1823 * short then padded with spaces).
1824 */
1825
1826static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1827{
1828 char *sp;
1829 int sigs, cnt;
1830
1831 sp = pos;
1832 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1833 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1834 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1835
1836 if (portp->stats.rxframing)
1837 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1838 if (portp->stats.rxparity)
1839 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1840 if (portp->stats.rxbreaks)
1841 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1842 if (portp->stats.rxoverrun)
1843 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1844
1845 sigs = stl_getsignals(portp);
1846 cnt = sprintf(sp, "%s%s%s%s%s ",
1847 (sigs & TIOCM_RTS) ? "|RTS" : "",
1848 (sigs & TIOCM_CTS) ? "|CTS" : "",
1849 (sigs & TIOCM_DTR) ? "|DTR" : "",
1850 (sigs & TIOCM_CD) ? "|DCD" : "",
1851 (sigs & TIOCM_DSR) ? "|DSR" : "");
1852 *sp = ' ';
1853 sp += cnt;
1854
1855 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1856 *sp++ = ' ';
1857 if (cnt >= MAXLINE)
1858 pos[(MAXLINE - 2)] = '+';
1859 pos[(MAXLINE - 1)] = '\n';
1860
014c2544 1861 return MAXLINE;
1da177e4
LT
1862}
1863
1864/*****************************************************************************/
1865
1866/*
1867 * Port info, read from the /proc file system.
1868 */
1869
1870static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1871{
1872 stlbrd_t *brdp;
1873 stlpanel_t *panelp;
1874 stlport_t *portp;
1875 int brdnr, panelnr, portnr, totalport;
1876 int curoff, maxoff;
1877 char *pos;
1878
1879#ifdef DEBUG
1880 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1881 "data=%x\n", (int) page, (int) start, (int) off, count,
1882 (int) eof, (int) data);
1883#endif
1884
1885 pos = page;
1886 totalport = 0;
1887 curoff = 0;
1888
1889 if (off == 0) {
1890 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1891 stl_drvversion);
1892 while (pos < (page + MAXLINE - 1))
1893 *pos++ = ' ';
1894 *pos++ = '\n';
1895 }
1896 curoff = MAXLINE;
1897
1898/*
1899 * We scan through for each board, panel and port. The offset is
1900 * calculated on the fly, and irrelevant ports are skipped.
1901 */
1902 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1903 brdp = stl_brds[brdnr];
1904 if (brdp == (stlbrd_t *) NULL)
1905 continue;
1906 if (brdp->state == 0)
1907 continue;
1908
1909 maxoff = curoff + (brdp->nrports * MAXLINE);
1910 if (off >= maxoff) {
1911 curoff = maxoff;
1912 continue;
1913 }
1914
1915 totalport = brdnr * STL_MAXPORTS;
1916 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1917 panelp = brdp->panels[panelnr];
1918 if (panelp == (stlpanel_t *) NULL)
1919 continue;
1920
1921 maxoff = curoff + (panelp->nrports * MAXLINE);
1922 if (off >= maxoff) {
1923 curoff = maxoff;
1924 totalport += panelp->nrports;
1925 continue;
1926 }
1927
1928 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1929 totalport++) {
1930 portp = panelp->ports[portnr];
1931 if (portp == (stlport_t *) NULL)
1932 continue;
1933 if (off >= (curoff += MAXLINE))
1934 continue;
1935 if ((pos - page + MAXLINE) > count)
1936 goto stl_readdone;
1937 pos += stl_portinfo(portp, totalport, pos);
1938 }
1939 }
1940 }
1941
1942 *eof = 1;
1943
1944stl_readdone:
1945 *start = page;
014c2544 1946 return (pos - page);
1da177e4
LT
1947}
1948
1949/*****************************************************************************/
1950
1951/*
1952 * All board interrupts are vectored through here first. This code then
1953 * calls off to the approrpriate board interrupt handlers.
1954 */
1955
1956static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
1957{
1958 stlbrd_t *brdp = (stlbrd_t *) dev_id;
1959
1960#ifdef DEBUG
1961 printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp, irq,
1962 (int) regs);
1963#endif
1964
1965 return IRQ_RETVAL((* brdp->isr)(brdp));
1966}
1967
1968/*****************************************************************************/
1969
1970/*
1971 * Interrupt service routine for EasyIO board types.
1972 */
1973
1974static int stl_eiointr(stlbrd_t *brdp)
1975{
1976 stlpanel_t *panelp;
1977 unsigned int iobase;
1978 int handled = 0;
1979
1980 panelp = brdp->panels[0];
1981 iobase = panelp->iobase;
1982 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1983 handled = 1;
1984 (* panelp->isr)(panelp, iobase);
1985 }
1986 return handled;
1987}
1988
1989/*****************************************************************************/
1990
1991/*
1992 * Interrupt service routine for ECH-AT board types.
1993 */
1994
1995static int stl_echatintr(stlbrd_t *brdp)
1996{
1997 stlpanel_t *panelp;
1998 unsigned int ioaddr;
1999 int bnknr;
2000 int handled = 0;
2001
2002 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2003
2004 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2005 handled = 1;
2006 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2007 ioaddr = brdp->bnkstataddr[bnknr];
2008 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2009 panelp = brdp->bnk2panel[bnknr];
2010 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2011 }
2012 }
2013 }
2014
2015 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2016
2017 return handled;
2018}
2019
2020/*****************************************************************************/
2021
2022/*
2023 * Interrupt service routine for ECH-MCA board types.
2024 */
2025
2026static int stl_echmcaintr(stlbrd_t *brdp)
2027{
2028 stlpanel_t *panelp;
2029 unsigned int ioaddr;
2030 int bnknr;
2031 int handled = 0;
2032
2033 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2034 handled = 1;
2035 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2036 ioaddr = brdp->bnkstataddr[bnknr];
2037 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2038 panelp = brdp->bnk2panel[bnknr];
2039 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2040 }
2041 }
2042 }
2043 return handled;
2044}
2045
2046/*****************************************************************************/
2047
2048/*
2049 * Interrupt service routine for ECH-PCI board types.
2050 */
2051
2052static int stl_echpciintr(stlbrd_t *brdp)
2053{
2054 stlpanel_t *panelp;
2055 unsigned int ioaddr;
2056 int bnknr, recheck;
2057 int handled = 0;
2058
2059 while (1) {
2060 recheck = 0;
2061 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2062 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2063 ioaddr = brdp->bnkstataddr[bnknr];
2064 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2065 panelp = brdp->bnk2panel[bnknr];
2066 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2067 recheck++;
2068 handled = 1;
2069 }
2070 }
2071 if (! recheck)
2072 break;
2073 }
2074 return handled;
2075}
2076
2077/*****************************************************************************/
2078
2079/*
2080 * Interrupt service routine for ECH-8/64-PCI board types.
2081 */
2082
2083static int stl_echpci64intr(stlbrd_t *brdp)
2084{
2085 stlpanel_t *panelp;
2086 unsigned int ioaddr;
2087 int bnknr;
2088 int handled = 0;
2089
2090 while (inb(brdp->ioctrl) & 0x1) {
2091 handled = 1;
2092 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2093 ioaddr = brdp->bnkstataddr[bnknr];
2094 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2095 panelp = brdp->bnk2panel[bnknr];
2096 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2097 }
2098 }
2099 }
2100
2101 return handled;
2102}
2103
2104/*****************************************************************************/
2105
2106/*
2107 * Service an off-level request for some channel.
2108 */
2109static void stl_offintr(void *private)
2110{
2111 stlport_t *portp;
2112 struct tty_struct *tty;
2113 unsigned int oldsigs;
2114
2115 portp = private;
2116
2117#ifdef DEBUG
2118 printk("stl_offintr(portp=%x)\n", (int) portp);
2119#endif
2120
2121 if (portp == (stlport_t *) NULL)
2122 return;
2123
2124 tty = portp->tty;
2125 if (tty == (struct tty_struct *) NULL)
2126 return;
2127
2128 lock_kernel();
2129 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2130 tty_wakeup(tty);
2131 }
2132 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2133 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2134 oldsigs = portp->sigs;
2135 portp->sigs = stl_getsignals(portp);
2136 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2137 wake_up_interruptible(&portp->open_wait);
2138 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2139 if (portp->flags & ASYNC_CHECK_CD)
2140 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2141 }
2142 }
2143 unlock_kernel();
2144}
2145
2146/*****************************************************************************/
2147
2148/*
2149 * Initialize all the ports on a panel.
2150 */
2151
2152static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2153{
2154 stlport_t *portp;
2155 int chipmask, i;
2156
2157#ifdef DEBUG
2158 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2159#endif
2160
2161 chipmask = stl_panelinit(brdp, panelp);
2162
2163/*
2164 * All UART's are initialized (if found!). Now go through and setup
2165 * each ports data structures.
2166 */
2167 for (i = 0; (i < panelp->nrports); i++) {
b0b4ed72
TK
2168 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
2169 if (!portp) {
1da177e4
LT
2170 printk("STALLION: failed to allocate memory "
2171 "(size=%d)\n", sizeof(stlport_t));
2172 break;
2173 }
1da177e4
LT
2174
2175 portp->magic = STL_PORTMAGIC;
2176 portp->portnr = i;
2177 portp->brdnr = panelp->brdnr;
2178 portp->panelnr = panelp->panelnr;
2179 portp->uartp = panelp->uartp;
2180 portp->clk = brdp->clk;
2181 portp->baud_base = STL_BAUDBASE;
2182 portp->close_delay = STL_CLOSEDELAY;
2183 portp->closing_wait = 30 * HZ;
2184 INIT_WORK(&portp->tqueue, stl_offintr, portp);
2185 init_waitqueue_head(&portp->open_wait);
2186 init_waitqueue_head(&portp->close_wait);
2187 portp->stats.brd = portp->brdnr;
2188 portp->stats.panel = portp->panelnr;
2189 portp->stats.port = portp->portnr;
2190 panelp->ports[i] = portp;
2191 stl_portinit(brdp, panelp, portp);
2192 }
2193
2194 return(0);
2195}
2196
2197/*****************************************************************************/
2198
2199/*
2200 * Try to find and initialize an EasyIO board.
2201 */
2202
2203static inline int stl_initeio(stlbrd_t *brdp)
2204{
2205 stlpanel_t *panelp;
2206 unsigned int status;
2207 char *name;
2208 int rc;
2209
2210#ifdef DEBUG
2211 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2212#endif
2213
2214 brdp->ioctrl = brdp->ioaddr1 + 1;
2215 brdp->iostatus = brdp->ioaddr1 + 2;
2216
2217 status = inb(brdp->iostatus);
2218 if ((status & EIO_IDBITMASK) == EIO_MK3)
2219 brdp->ioctrl++;
2220
2221/*
2222 * Handle board specific stuff now. The real difference is PCI
2223 * or not PCI.
2224 */
2225 if (brdp->brdtype == BRD_EASYIOPCI) {
2226 brdp->iosize1 = 0x80;
2227 brdp->iosize2 = 0x80;
2228 name = "serial(EIO-PCI)";
2229 outb(0x41, (brdp->ioaddr2 + 0x4c));
2230 } else {
2231 brdp->iosize1 = 8;
2232 name = "serial(EIO)";
2233 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2234 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2235 printk("STALLION: invalid irq=%d for brd=%d\n",
2236 brdp->irq, brdp->brdnr);
2237 return(-EINVAL);
2238 }
2239 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2240 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2241 brdp->ioctrl);
2242 }
2243
2244 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2245 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2246 "%x conflicts with another device\n", brdp->brdnr,
2247 brdp->ioaddr1);
2248 return(-EBUSY);
2249 }
2250
2251 if (brdp->iosize2 > 0)
2252 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2253 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2254 "address %x conflicts with another device\n",
2255 brdp->brdnr, brdp->ioaddr2);
2256 printk(KERN_WARNING "STALLION: Warning, also "
2257 "releasing board %d I/O address %x \n",
2258 brdp->brdnr, brdp->ioaddr1);
2259 release_region(brdp->ioaddr1, brdp->iosize1);
2260 return(-EBUSY);
2261 }
2262
2263/*
2264 * Everything looks OK, so let's go ahead and probe for the hardware.
2265 */
2266 brdp->clk = CD1400_CLK;
2267 brdp->isr = stl_eiointr;
2268
2269 switch (status & EIO_IDBITMASK) {
2270 case EIO_8PORTM:
2271 brdp->clk = CD1400_CLK8M;
2272 /* fall thru */
2273 case EIO_8PORTRS:
2274 case EIO_8PORTDI:
2275 brdp->nrports = 8;
2276 break;
2277 case EIO_4PORTRS:
2278 brdp->nrports = 4;
2279 break;
2280 case EIO_MK3:
2281 switch (status & EIO_BRDMASK) {
2282 case ID_BRD4:
2283 brdp->nrports = 4;
2284 break;
2285 case ID_BRD8:
2286 brdp->nrports = 8;
2287 break;
2288 case ID_BRD16:
2289 brdp->nrports = 16;
2290 break;
2291 default:
2292 return(-ENODEV);
2293 }
2294 break;
2295 default:
2296 return(-ENODEV);
2297 }
2298
2299/*
2300 * We have verified that the board is actually present, so now we
2301 * can complete the setup.
2302 */
2303
b0b4ed72
TK
2304 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2305 if (!panelp) {
1da177e4
LT
2306 printk(KERN_WARNING "STALLION: failed to allocate memory "
2307 "(size=%d)\n", sizeof(stlpanel_t));
b0b4ed72 2308 return -ENOMEM;
1da177e4 2309 }
1da177e4
LT
2310
2311 panelp->magic = STL_PANELMAGIC;
2312 panelp->brdnr = brdp->brdnr;
2313 panelp->panelnr = 0;
2314 panelp->nrports = brdp->nrports;
2315 panelp->iobase = brdp->ioaddr1;
2316 panelp->hwid = status;
2317 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2318 panelp->uartp = (void *) &stl_sc26198uart;
2319 panelp->isr = stl_sc26198intr;
2320 } else {
2321 panelp->uartp = (void *) &stl_cd1400uart;
2322 panelp->isr = stl_cd1400eiointr;
2323 }
2324
2325 brdp->panels[0] = panelp;
2326 brdp->nrpanels = 1;
2327 brdp->state |= BRD_FOUND;
2328 brdp->hwid = status;
2329 if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
2330 printk("STALLION: failed to register interrupt "
2331 "routine for %s irq=%d\n", name, brdp->irq);
2332 rc = -ENODEV;
2333 } else {
2334 rc = 0;
2335 }
014c2544 2336 return rc;
1da177e4
LT
2337}
2338
2339/*****************************************************************************/
2340
2341/*
2342 * Try to find an ECH board and initialize it. This code is capable of
2343 * dealing with all types of ECH board.
2344 */
2345
2346static inline int stl_initech(stlbrd_t *brdp)
2347{
2348 stlpanel_t *panelp;
2349 unsigned int status, nxtid, ioaddr, conflict;
2350 int panelnr, banknr, i;
2351 char *name;
2352
2353#ifdef DEBUG
2354 printk("stl_initech(brdp=%x)\n", (int) brdp);
2355#endif
2356
2357 status = 0;
2358 conflict = 0;
2359
2360/*
2361 * Set up the initial board register contents for boards. This varies a
2362 * bit between the different board types. So we need to handle each
2363 * separately. Also do a check that the supplied IRQ is good.
2364 */
2365 switch (brdp->brdtype) {
2366
2367 case BRD_ECH:
2368 brdp->isr = stl_echatintr;
2369 brdp->ioctrl = brdp->ioaddr1 + 1;
2370 brdp->iostatus = brdp->ioaddr1 + 1;
2371 status = inb(brdp->iostatus);
2372 if ((status & ECH_IDBITMASK) != ECH_ID)
2373 return(-ENODEV);
2374 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2375 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2376 printk("STALLION: invalid irq=%d for brd=%d\n",
2377 brdp->irq, brdp->brdnr);
2378 return(-EINVAL);
2379 }
2380 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2381 status |= (stl_vecmap[brdp->irq] << 1);
2382 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2383 brdp->ioctrlval = ECH_INTENABLE |
2384 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2385 for (i = 0; (i < 10); i++)
2386 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2387 brdp->iosize1 = 2;
2388 brdp->iosize2 = 32;
2389 name = "serial(EC8/32)";
2390 outb(status, brdp->ioaddr1);
2391 break;
2392
2393 case BRD_ECHMC:
2394 brdp->isr = stl_echmcaintr;
2395 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2396 brdp->iostatus = brdp->ioctrl;
2397 status = inb(brdp->iostatus);
2398 if ((status & ECH_IDBITMASK) != ECH_ID)
2399 return(-ENODEV);
2400 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2401 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2402 printk("STALLION: invalid irq=%d for brd=%d\n",
2403 brdp->irq, brdp->brdnr);
2404 return(-EINVAL);
2405 }
2406 outb(ECHMC_BRDRESET, brdp->ioctrl);
2407 outb(ECHMC_INTENABLE, brdp->ioctrl);
2408 brdp->iosize1 = 64;
2409 name = "serial(EC8/32-MC)";
2410 break;
2411
2412 case BRD_ECHPCI:
2413 brdp->isr = stl_echpciintr;
2414 brdp->ioctrl = brdp->ioaddr1 + 2;
2415 brdp->iosize1 = 4;
2416 brdp->iosize2 = 8;
2417 name = "serial(EC8/32-PCI)";
2418 break;
2419
2420 case BRD_ECH64PCI:
2421 brdp->isr = stl_echpci64intr;
2422 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2423 outb(0x43, (brdp->ioaddr1 + 0x4c));
2424 brdp->iosize1 = 0x80;
2425 brdp->iosize2 = 0x80;
2426 name = "serial(EC8/64-PCI)";
2427 break;
2428
2429 default:
2430 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2431 return(-EINVAL);
2432 break;
2433 }
2434
2435/*
2436 * Check boards for possible IO address conflicts and return fail status
2437 * if an IO conflict found.
2438 */
2439 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2440 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2441 "%x conflicts with another device\n", brdp->brdnr,
2442 brdp->ioaddr1);
2443 return(-EBUSY);
2444 }
2445
2446 if (brdp->iosize2 > 0)
2447 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2448 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2449 "address %x conflicts with another device\n",
2450 brdp->brdnr, brdp->ioaddr2);
2451 printk(KERN_WARNING "STALLION: Warning, also "
2452 "releasing board %d I/O address %x \n",
2453 brdp->brdnr, brdp->ioaddr1);
2454 release_region(brdp->ioaddr1, brdp->iosize1);
2455 return(-EBUSY);
2456 }
2457
2458/*
2459 * Scan through the secondary io address space looking for panels.
2460 * As we find'em allocate and initialize panel structures for each.
2461 */
2462 brdp->clk = CD1400_CLK;
2463 brdp->hwid = status;
2464
2465 ioaddr = brdp->ioaddr2;
2466 banknr = 0;
2467 panelnr = 0;
2468 nxtid = 0;
2469
2470 for (i = 0; (i < STL_MAXPANELS); i++) {
2471 if (brdp->brdtype == BRD_ECHPCI) {
2472 outb(nxtid, brdp->ioctrl);
2473 ioaddr = brdp->ioaddr2;
2474 }
2475 status = inb(ioaddr + ECH_PNLSTATUS);
2476 if ((status & ECH_PNLIDMASK) != nxtid)
2477 break;
b0b4ed72
TK
2478 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2479 if (!panelp) {
1da177e4
LT
2480 printk("STALLION: failed to allocate memory "
2481 "(size=%d)\n", sizeof(stlpanel_t));
2482 break;
2483 }
1da177e4
LT
2484 panelp->magic = STL_PANELMAGIC;
2485 panelp->brdnr = brdp->brdnr;
2486 panelp->panelnr = panelnr;
2487 panelp->iobase = ioaddr;
2488 panelp->pagenr = nxtid;
2489 panelp->hwid = status;
2490 brdp->bnk2panel[banknr] = panelp;
2491 brdp->bnkpageaddr[banknr] = nxtid;
2492 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2493
2494 if (status & ECH_PNLXPID) {
2495 panelp->uartp = (void *) &stl_sc26198uart;
2496 panelp->isr = stl_sc26198intr;
2497 if (status & ECH_PNL16PORT) {
2498 panelp->nrports = 16;
2499 brdp->bnk2panel[banknr] = panelp;
2500 brdp->bnkpageaddr[banknr] = nxtid;
2501 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2502 ECH_PNLSTATUS;
2503 } else {
2504 panelp->nrports = 8;
2505 }
2506 } else {
2507 panelp->uartp = (void *) &stl_cd1400uart;
2508 panelp->isr = stl_cd1400echintr;
2509 if (status & ECH_PNL16PORT) {
2510 panelp->nrports = 16;
2511 panelp->ackmask = 0x80;
2512 if (brdp->brdtype != BRD_ECHPCI)
2513 ioaddr += EREG_BANKSIZE;
2514 brdp->bnk2panel[banknr] = panelp;
2515 brdp->bnkpageaddr[banknr] = ++nxtid;
2516 brdp->bnkstataddr[banknr++] = ioaddr +
2517 ECH_PNLSTATUS;
2518 } else {
2519 panelp->nrports = 8;
2520 panelp->ackmask = 0xc0;
2521 }
2522 }
2523
2524 nxtid++;
2525 ioaddr += EREG_BANKSIZE;
2526 brdp->nrports += panelp->nrports;
2527 brdp->panels[panelnr++] = panelp;
2528 if ((brdp->brdtype != BRD_ECHPCI) &&
2529 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2530 break;
2531 }
2532
2533 brdp->nrpanels = panelnr;
2534 brdp->nrbnks = banknr;
2535 if (brdp->brdtype == BRD_ECH)
2536 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2537
2538 brdp->state |= BRD_FOUND;
2539 if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
2540 printk("STALLION: failed to register interrupt "
2541 "routine for %s irq=%d\n", name, brdp->irq);
2542 i = -ENODEV;
2543 } else {
2544 i = 0;
2545 }
2546
2547 return(i);
2548}
2549
2550/*****************************************************************************/
2551
2552/*
2553 * Initialize and configure the specified board.
2554 * Scan through all the boards in the configuration and see what we
2555 * can find. Handle EIO and the ECH boards a little differently here
2556 * since the initial search and setup is very different.
2557 */
2558
2559static int __init stl_brdinit(stlbrd_t *brdp)
2560{
2561 int i;
2562
2563#ifdef DEBUG
2564 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2565#endif
2566
2567 switch (brdp->brdtype) {
2568 case BRD_EASYIO:
2569 case BRD_EASYIOPCI:
2570 stl_initeio(brdp);
2571 break;
2572 case BRD_ECH:
2573 case BRD_ECHMC:
2574 case BRD_ECHPCI:
2575 case BRD_ECH64PCI:
2576 stl_initech(brdp);
2577 break;
2578 default:
2579 printk("STALLION: board=%d is unknown board type=%d\n",
2580 brdp->brdnr, brdp->brdtype);
2581 return(ENODEV);
2582 }
2583
2584 stl_brds[brdp->brdnr] = brdp;
2585 if ((brdp->state & BRD_FOUND) == 0) {
2586 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2587 stl_brdnames[brdp->brdtype], brdp->brdnr,
2588 brdp->ioaddr1, brdp->irq);
2589 return(ENODEV);
2590 }
2591
2592 for (i = 0; (i < STL_MAXPANELS); i++)
2593 if (brdp->panels[i] != (stlpanel_t *) NULL)
2594 stl_initports(brdp, brdp->panels[i]);
2595
2596 printk("STALLION: %s found, board=%d io=%x irq=%d "
2597 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2598 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2599 brdp->nrports);
2600 return(0);
2601}
2602
2603/*****************************************************************************/
2604
2605/*
2606 * Find the next available board number that is free.
2607 */
2608
2609static inline int stl_getbrdnr(void)
2610{
2611 int i;
2612
2613 for (i = 0; (i < STL_MAXBRDS); i++) {
2614 if (stl_brds[i] == (stlbrd_t *) NULL) {
2615 if (i >= stl_nrbrds)
2616 stl_nrbrds = i + 1;
2617 return(i);
2618 }
2619 }
2620 return(-1);
2621}
2622
2623/*****************************************************************************/
2624
2625#ifdef CONFIG_PCI
2626
2627/*
2628 * We have a Stallion board. Allocate a board structure and
2629 * initialize it. Read its IO and IRQ resources from PCI
2630 * configuration space.
2631 */
2632
2633static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2634{
2635 stlbrd_t *brdp;
2636
2637#ifdef DEBUG
2638 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2639 devp->bus->number, devp->devfn);
2640#endif
2641
2642 if (pci_enable_device(devp))
2643 return(-EIO);
2644 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2645 return(-ENOMEM);
2646 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2647 printk("STALLION: too many boards found, "
2648 "maximum supported %d\n", STL_MAXBRDS);
2649 return(0);
2650 }
2651 brdp->brdtype = brdtype;
2652
2653/*
2654 * Different Stallion boards use the BAR registers in different ways,
2655 * so set up io addresses based on board type.
2656 */
2657#ifdef DEBUG
2658 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2659 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2660 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2661#endif
2662
2663/*
2664 * We have all resources from the board, so let's setup the actual
2665 * board structure now.
2666 */
2667 switch (brdtype) {
2668 case BRD_ECHPCI:
2669 brdp->ioaddr2 = pci_resource_start(devp, 0);
2670 brdp->ioaddr1 = pci_resource_start(devp, 1);
2671 break;
2672 case BRD_ECH64PCI:
2673 brdp->ioaddr2 = pci_resource_start(devp, 2);
2674 brdp->ioaddr1 = pci_resource_start(devp, 1);
2675 break;
2676 case BRD_EASYIOPCI:
2677 brdp->ioaddr1 = pci_resource_start(devp, 2);
2678 brdp->ioaddr2 = pci_resource_start(devp, 1);
2679 break;
2680 default:
2681 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2682 break;
2683 }
2684
2685 brdp->irq = devp->irq;
2686 stl_brdinit(brdp);
2687
2688 return(0);
2689}
2690
2691/*****************************************************************************/
2692
2693/*
2694 * Find all Stallion PCI boards that might be installed. Initialize each
2695 * one as it is found.
2696 */
2697
2698
2699static inline int stl_findpcibrds(void)
2700{
2701 struct pci_dev *dev = NULL;
2702 int i, rc;
2703
2704#ifdef DEBUG
2705 printk("stl_findpcibrds()\n");
2706#endif
2707
2708 for (i = 0; (i < stl_nrpcibrds); i++)
2709 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2710 stl_pcibrds[i].devid, dev))) {
2711
2712/*
2713 * Found a device on the PCI bus that has our vendor and
2714 * device ID. Need to check now that it is really us.
2715 */
2716 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2717 continue;
2718
2719 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2720 if (rc)
2721 return(rc);
2722 }
2723
2724 return(0);
2725}
2726
2727#endif
2728
2729/*****************************************************************************/
2730
2731/*
2732 * Scan through all the boards in the configuration and see what we
2733 * can find. Handle EIO and the ECH boards a little differently here
2734 * since the initial search and setup is too different.
2735 */
2736
2737static inline int stl_initbrds(void)
2738{
2739 stlbrd_t *brdp;
2740 stlconf_t *confp;
2741 int i;
2742
2743#ifdef DEBUG
2744 printk("stl_initbrds()\n");
2745#endif
2746
2747 if (stl_nrbrds > STL_MAXBRDS) {
2748 printk("STALLION: too many boards in configuration table, "
2749 "truncating to %d\n", STL_MAXBRDS);
2750 stl_nrbrds = STL_MAXBRDS;
2751 }
2752
2753/*
2754 * Firstly scan the list of static boards configured. Allocate
2755 * resources and initialize the boards as found.
2756 */
2757 for (i = 0; (i < stl_nrbrds); i++) {
2758 confp = &stl_brdconf[i];
2759 stl_parsebrd(confp, stl_brdsp[i]);
2760 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2761 return(-ENOMEM);
2762 brdp->brdnr = i;
2763 brdp->brdtype = confp->brdtype;
2764 brdp->ioaddr1 = confp->ioaddr1;
2765 brdp->ioaddr2 = confp->ioaddr2;
2766 brdp->irq = confp->irq;
2767 brdp->irqtype = confp->irqtype;
2768 stl_brdinit(brdp);
2769 }
2770
2771/*
2772 * Find any dynamically supported boards. That is via module load
2773 * line options or auto-detected on the PCI bus.
2774 */
2775 stl_argbrds();
2776#ifdef CONFIG_PCI
2777 stl_findpcibrds();
2778#endif
2779
2780 return(0);
2781}
2782
2783/*****************************************************************************/
2784
2785/*
2786 * Return the board stats structure to user app.
2787 */
2788
2789static int stl_getbrdstats(combrd_t __user *bp)
2790{
2791 stlbrd_t *brdp;
2792 stlpanel_t *panelp;
2793 int i;
2794
2795 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2796 return -EFAULT;
2797 if (stl_brdstats.brd >= STL_MAXBRDS)
2798 return(-ENODEV);
2799 brdp = stl_brds[stl_brdstats.brd];
2800 if (brdp == (stlbrd_t *) NULL)
2801 return(-ENODEV);
2802
2803 memset(&stl_brdstats, 0, sizeof(combrd_t));
2804 stl_brdstats.brd = brdp->brdnr;
2805 stl_brdstats.type = brdp->brdtype;
2806 stl_brdstats.hwid = brdp->hwid;
2807 stl_brdstats.state = brdp->state;
2808 stl_brdstats.ioaddr = brdp->ioaddr1;
2809 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2810 stl_brdstats.irq = brdp->irq;
2811 stl_brdstats.nrpanels = brdp->nrpanels;
2812 stl_brdstats.nrports = brdp->nrports;
2813 for (i = 0; (i < brdp->nrpanels); i++) {
2814 panelp = brdp->panels[i];
2815 stl_brdstats.panels[i].panel = i;
2816 stl_brdstats.panels[i].hwid = panelp->hwid;
2817 stl_brdstats.panels[i].nrports = panelp->nrports;
2818 }
2819
2820 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2821}
2822
2823/*****************************************************************************/
2824
2825/*
2826 * Resolve the referenced port number into a port struct pointer.
2827 */
2828
2829static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2830{
2831 stlbrd_t *brdp;
2832 stlpanel_t *panelp;
2833
2834 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2835 return((stlport_t *) NULL);
2836 brdp = stl_brds[brdnr];
2837 if (brdp == (stlbrd_t *) NULL)
2838 return((stlport_t *) NULL);
2839 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2840 return((stlport_t *) NULL);
2841 panelp = brdp->panels[panelnr];
2842 if (panelp == (stlpanel_t *) NULL)
2843 return((stlport_t *) NULL);
2844 if ((portnr < 0) || (portnr >= panelp->nrports))
2845 return((stlport_t *) NULL);
2846 return(panelp->ports[portnr]);
2847}
2848
2849/*****************************************************************************/
2850
2851/*
2852 * Return the port stats structure to user app. A NULL port struct
2853 * pointer passed in means that we need to find out from the app
2854 * what port to get stats for (used through board control device).
2855 */
2856
2857static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2858{
2859 unsigned char *head, *tail;
2860 unsigned long flags;
2861
2862 if (!portp) {
2863 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2864 return -EFAULT;
2865 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2866 stl_comstats.port);
2867 if (portp == (stlport_t *) NULL)
2868 return(-ENODEV);
2869 }
2870
2871 portp->stats.state = portp->istate;
2872 portp->stats.flags = portp->flags;
2873 portp->stats.hwid = portp->hwid;
2874
2875 portp->stats.ttystate = 0;
2876 portp->stats.cflags = 0;
2877 portp->stats.iflags = 0;
2878 portp->stats.oflags = 0;
2879 portp->stats.lflags = 0;
2880 portp->stats.rxbuffered = 0;
2881
2882 save_flags(flags);
2883 cli();
2884 if (portp->tty != (struct tty_struct *) NULL) {
2885 if (portp->tty->driver_data == portp) {
2886 portp->stats.ttystate = portp->tty->flags;
33f0f88f
AC
2887 /* No longer available as a statistic */
2888 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
1da177e4
LT
2889 if (portp->tty->termios != (struct termios *) NULL) {
2890 portp->stats.cflags = portp->tty->termios->c_cflag;
2891 portp->stats.iflags = portp->tty->termios->c_iflag;
2892 portp->stats.oflags = portp->tty->termios->c_oflag;
2893 portp->stats.lflags = portp->tty->termios->c_lflag;
2894 }
2895 }
2896 }
2897 restore_flags(flags);
2898
2899 head = portp->tx.head;
2900 tail = portp->tx.tail;
2901 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2902 (STL_TXBUFSIZE - (tail - head)));
2903
2904 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2905
2906 return copy_to_user(cp, &portp->stats,
2907 sizeof(comstats_t)) ? -EFAULT : 0;
2908}
2909
2910/*****************************************************************************/
2911
2912/*
2913 * Clear the port stats structure. We also return it zeroed out...
2914 */
2915
2916static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
2917{
2918 if (!portp) {
2919 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2920 return -EFAULT;
2921 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2922 stl_comstats.port);
2923 if (portp == (stlport_t *) NULL)
2924 return(-ENODEV);
2925 }
2926
2927 memset(&portp->stats, 0, sizeof(comstats_t));
2928 portp->stats.brd = portp->brdnr;
2929 portp->stats.panel = portp->panelnr;
2930 portp->stats.port = portp->portnr;
2931 return copy_to_user(cp, &portp->stats,
2932 sizeof(comstats_t)) ? -EFAULT : 0;
2933}
2934
2935/*****************************************************************************/
2936
2937/*
2938 * Return the entire driver ports structure to a user app.
2939 */
2940
2941static int stl_getportstruct(stlport_t __user *arg)
2942{
2943 stlport_t *portp;
2944
2945 if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
2946 return -EFAULT;
2947 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2948 stl_dummyport.portnr);
2949 if (!portp)
2950 return -ENODEV;
2951 return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
2952}
2953
2954/*****************************************************************************/
2955
2956/*
2957 * Return the entire driver board structure to a user app.
2958 */
2959
2960static int stl_getbrdstruct(stlbrd_t __user *arg)
2961{
2962 stlbrd_t *brdp;
2963
2964 if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
2965 return -EFAULT;
2966 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
2967 return -ENODEV;
2968 brdp = stl_brds[stl_dummybrd.brdnr];
2969 if (!brdp)
2970 return(-ENODEV);
2971 return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
2972}
2973
2974/*****************************************************************************/
2975
2976/*
2977 * The "staliomem" device is also required to do some special operations
2978 * on the board and/or ports. In this driver it is mostly used for stats
2979 * collection.
2980 */
2981
2982static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2983{
2984 int brdnr, rc;
2985 void __user *argp = (void __user *)arg;
2986
2987#ifdef DEBUG
2988 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
2989 (int) fp, cmd, (int) arg);
2990#endif
2991
2992 brdnr = iminor(ip);
2993 if (brdnr >= STL_MAXBRDS)
2994 return(-ENODEV);
2995 rc = 0;
2996
2997 switch (cmd) {
2998 case COM_GETPORTSTATS:
2999 rc = stl_getportstats(NULL, argp);
3000 break;
3001 case COM_CLRPORTSTATS:
3002 rc = stl_clrportstats(NULL, argp);
3003 break;
3004 case COM_GETBRDSTATS:
3005 rc = stl_getbrdstats(argp);
3006 break;
3007 case COM_READPORT:
3008 rc = stl_getportstruct(argp);
3009 break;
3010 case COM_READBOARD:
3011 rc = stl_getbrdstruct(argp);
3012 break;
3013 default:
3014 rc = -ENOIOCTLCMD;
3015 break;
3016 }
3017
3018 return(rc);
3019}
3020
3021static struct tty_operations stl_ops = {
3022 .open = stl_open,
3023 .close = stl_close,
3024 .write = stl_write,
3025 .put_char = stl_putchar,
3026 .flush_chars = stl_flushchars,
3027 .write_room = stl_writeroom,
3028 .chars_in_buffer = stl_charsinbuffer,
3029 .ioctl = stl_ioctl,
3030 .set_termios = stl_settermios,
3031 .throttle = stl_throttle,
3032 .unthrottle = stl_unthrottle,
3033 .stop = stl_stop,
3034 .start = stl_start,
3035 .hangup = stl_hangup,
3036 .flush_buffer = stl_flushbuffer,
3037 .break_ctl = stl_breakctl,
3038 .wait_until_sent = stl_waituntilsent,
3039 .send_xchar = stl_sendxchar,
3040 .read_proc = stl_readproc,
3041 .tiocmget = stl_tiocmget,
3042 .tiocmset = stl_tiocmset,
3043};
3044
3045/*****************************************************************************/
3046
408b664a 3047static int __init stl_init(void)
1da177e4
LT
3048{
3049 int i;
3050 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3051
3052 stl_initbrds();
3053
3054 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3055 if (!stl_serial)
3056 return -1;
3057
3058/*
3059 * Allocate a temporary write buffer.
3060 */
b0b4ed72
TK
3061 stl_tmpwritebuf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
3062 if (!stl_tmpwritebuf)
1da177e4
LT
3063 printk("STALLION: failed to allocate memory (size=%d)\n",
3064 STL_TXBUFSIZE);
3065
3066/*
3067 * Set up a character driver for per board stuff. This is mainly used
3068 * to do stats ioctls on the ports.
3069 */
3070 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3071 printk("STALLION: failed to register serial board device\n");
1da177e4 3072
ca8eca68 3073 stallion_class = class_create(THIS_MODULE, "staliomem");
7c69ef79 3074 for (i = 0; i < 4; i++)
53f46542
GKH
3075 class_device_create(stallion_class, NULL,
3076 MKDEV(STL_SIOMEMMAJOR, i), NULL,
3077 "staliomem%d", i);
1da177e4
LT
3078
3079 stl_serial->owner = THIS_MODULE;
3080 stl_serial->driver_name = stl_drvname;
3081 stl_serial->name = "ttyE";
3082 stl_serial->devfs_name = "tts/E";
3083 stl_serial->major = STL_SERIALMAJOR;
3084 stl_serial->minor_start = 0;
3085 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3086 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3087 stl_serial->init_termios = stl_deftermios;
3088 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3089 tty_set_operations(stl_serial, &stl_ops);
3090
3091 if (tty_register_driver(stl_serial)) {
3092 put_tty_driver(stl_serial);
3093 printk("STALLION: failed to register serial driver\n");
3094 return -1;
3095 }
3096
014c2544 3097 return 0;
1da177e4
LT
3098}
3099
3100/*****************************************************************************/
3101/* CD1400 HARDWARE FUNCTIONS */
3102/*****************************************************************************/
3103
3104/*
3105 * These functions get/set/update the registers of the cd1400 UARTs.
3106 * Access to the cd1400 registers is via an address/data io port pair.
3107 * (Maybe should make this inline...)
3108 */
3109
3110static int stl_cd1400getreg(stlport_t *portp, int regnr)
3111{
3112 outb((regnr + portp->uartaddr), portp->ioaddr);
014c2544 3113 return inb(portp->ioaddr + EREG_DATA);
1da177e4
LT
3114}
3115
3116static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3117{
3118 outb((regnr + portp->uartaddr), portp->ioaddr);
3119 outb(value, portp->ioaddr + EREG_DATA);
3120}
3121
3122static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3123{
3124 outb((regnr + portp->uartaddr), portp->ioaddr);
3125 if (inb(portp->ioaddr + EREG_DATA) != value) {
3126 outb(value, portp->ioaddr + EREG_DATA);
014c2544 3127 return 1;
1da177e4 3128 }
014c2544 3129 return 0;
1da177e4
LT
3130}
3131
3132/*****************************************************************************/
3133
3134/*
3135 * Inbitialize the UARTs in a panel. We don't care what sort of board
3136 * these ports are on - since the port io registers are almost
3137 * identical when dealing with ports.
3138 */
3139
3140static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3141{
3142 unsigned int gfrcr;
3143 int chipmask, i, j;
3144 int nrchips, uartaddr, ioaddr;
3145
3146#ifdef DEBUG
3147 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3148#endif
3149
3150 BRDENABLE(panelp->brdnr, panelp->pagenr);
3151
3152/*
3153 * Check that each chip is present and started up OK.
3154 */
3155 chipmask = 0;
3156 nrchips = panelp->nrports / CD1400_PORTS;
3157 for (i = 0; (i < nrchips); i++) {
3158 if (brdp->brdtype == BRD_ECHPCI) {
3159 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3160 ioaddr = panelp->iobase;
3161 } else {
3162 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3163 }
3164 uartaddr = (i & 0x01) ? 0x080 : 0;
3165 outb((GFRCR + uartaddr), ioaddr);
3166 outb(0, (ioaddr + EREG_DATA));
3167 outb((CCR + uartaddr), ioaddr);
3168 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3169 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3170 outb((GFRCR + uartaddr), ioaddr);
3171 for (j = 0; (j < CCR_MAXWAIT); j++) {
3172 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3173 break;
3174 }
3175 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3176 printk("STALLION: cd1400 not responding, "
3177 "brd=%d panel=%d chip=%d\n",
3178 panelp->brdnr, panelp->panelnr, i);
3179 continue;
3180 }
3181 chipmask |= (0x1 << i);
3182 outb((PPR + uartaddr), ioaddr);
3183 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3184 }
3185
3186 BRDDISABLE(panelp->brdnr);
014c2544 3187 return chipmask;
1da177e4
LT
3188}
3189
3190/*****************************************************************************/
3191
3192/*
3193 * Initialize hardware specific port registers.
3194 */
3195
3196static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3197{
3198#ifdef DEBUG
3199 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3200 (int) brdp, (int) panelp, (int) portp);
3201#endif
3202
3203 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3204 (portp == (stlport_t *) NULL))
3205 return;
3206
3207 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3208 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3209 portp->uartaddr = (portp->portnr & 0x04) << 5;
3210 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3211
3212 BRDENABLE(portp->brdnr, portp->pagenr);
3213 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3214 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3215 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3216 BRDDISABLE(portp->brdnr);
3217}
3218
3219/*****************************************************************************/
3220
3221/*
3222 * Wait for the command register to be ready. We will poll this,
3223 * since it won't usually take too long to be ready.
3224 */
3225
3226static void stl_cd1400ccrwait(stlport_t *portp)
3227{
3228 int i;
3229
3230 for (i = 0; (i < CCR_MAXWAIT); i++) {
3231 if (stl_cd1400getreg(portp, CCR) == 0) {
3232 return;
3233 }
3234 }
3235
3236 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3237 portp->portnr, portp->panelnr, portp->brdnr);
3238}
3239
3240/*****************************************************************************/
3241
3242/*
3243 * Set up the cd1400 registers for a port based on the termios port
3244 * settings.
3245 */
3246
3247static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3248{
3249 stlbrd_t *brdp;
3250 unsigned long flags;
3251 unsigned int clkdiv, baudrate;
3252 unsigned char cor1, cor2, cor3;
3253 unsigned char cor4, cor5, ccr;
3254 unsigned char srer, sreron, sreroff;
3255 unsigned char mcor1, mcor2, rtpr;
3256 unsigned char clk, div;
3257
3258 cor1 = 0;
3259 cor2 = 0;
3260 cor3 = 0;
3261 cor4 = 0;
3262 cor5 = 0;
3263 ccr = 0;
3264 rtpr = 0;
3265 clk = 0;
3266 div = 0;
3267 mcor1 = 0;
3268 mcor2 = 0;
3269 sreron = 0;
3270 sreroff = 0;
3271
3272 brdp = stl_brds[portp->brdnr];
3273 if (brdp == (stlbrd_t *) NULL)
3274 return;
3275
3276/*
3277 * Set up the RX char ignore mask with those RX error types we
3278 * can ignore. We can get the cd1400 to help us out a little here,
3279 * it will ignore parity errors and breaks for us.
3280 */
3281 portp->rxignoremsk = 0;
3282 if (tiosp->c_iflag & IGNPAR) {
3283 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3284 cor1 |= COR1_PARIGNORE;
3285 }
3286 if (tiosp->c_iflag & IGNBRK) {
3287 portp->rxignoremsk |= ST_BREAK;
3288 cor4 |= COR4_IGNBRK;
3289 }
3290
3291 portp->rxmarkmsk = ST_OVERRUN;
3292 if (tiosp->c_iflag & (INPCK | PARMRK))
3293 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3294 if (tiosp->c_iflag & BRKINT)
3295 portp->rxmarkmsk |= ST_BREAK;
3296
3297/*
3298 * Go through the char size, parity and stop bits and set all the
3299 * option register appropriately.
3300 */
3301 switch (tiosp->c_cflag & CSIZE) {
3302 case CS5:
3303 cor1 |= COR1_CHL5;
3304 break;
3305 case CS6:
3306 cor1 |= COR1_CHL6;
3307 break;
3308 case CS7:
3309 cor1 |= COR1_CHL7;
3310 break;
3311 default:
3312 cor1 |= COR1_CHL8;
3313 break;
3314 }
3315
3316 if (tiosp->c_cflag & CSTOPB)
3317 cor1 |= COR1_STOP2;
3318 else
3319 cor1 |= COR1_STOP1;
3320
3321 if (tiosp->c_cflag & PARENB) {
3322 if (tiosp->c_cflag & PARODD)
3323 cor1 |= (COR1_PARENB | COR1_PARODD);
3324 else
3325 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3326 } else {
3327 cor1 |= COR1_PARNONE;
3328 }
3329
3330/*
3331 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3332 * space for hardware flow control and the like. This should be set to
3333 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3334 * really be based on VTIME.
3335 */
3336 cor3 |= FIFO_RXTHRESHOLD;
3337 rtpr = 2;
3338
3339/*
3340 * Calculate the baud rate timers. For now we will just assume that
3341 * the input and output baud are the same. Could have used a baud
3342 * table here, but this way we can generate virtually any baud rate
3343 * we like!
3344 */
3345 baudrate = tiosp->c_cflag & CBAUD;
3346 if (baudrate & CBAUDEX) {
3347 baudrate &= ~CBAUDEX;
3348 if ((baudrate < 1) || (baudrate > 4))
3349 tiosp->c_cflag &= ~CBAUDEX;
3350 else
3351 baudrate += 15;
3352 }
3353 baudrate = stl_baudrates[baudrate];
3354 if ((tiosp->c_cflag & CBAUD) == B38400) {
3355 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3356 baudrate = 57600;
3357 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3358 baudrate = 115200;
3359 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3360 baudrate = 230400;
3361 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3362 baudrate = 460800;
3363 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3364 baudrate = (portp->baud_base / portp->custom_divisor);
3365 }
3366 if (baudrate > STL_CD1400MAXBAUD)
3367 baudrate = STL_CD1400MAXBAUD;
3368
3369 if (baudrate > 0) {
3370 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3371 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3372 if (clkdiv < 0x100)
3373 break;
3374 }
3375 div = (unsigned char) clkdiv;
3376 }
3377
3378/*
3379 * Check what form of modem signaling is required and set it up.
3380 */
3381 if ((tiosp->c_cflag & CLOCAL) == 0) {
3382 mcor1 |= MCOR1_DCD;
3383 mcor2 |= MCOR2_DCD;
3384 sreron |= SRER_MODEM;
3385 portp->flags |= ASYNC_CHECK_CD;
3386 } else {
3387 portp->flags &= ~ASYNC_CHECK_CD;
3388 }
3389
3390/*
3391 * Setup cd1400 enhanced modes if we can. In particular we want to
3392 * handle as much of the flow control as possible automatically. As
3393 * well as saving a few CPU cycles it will also greatly improve flow
3394 * control reliability.
3395 */
3396 if (tiosp->c_iflag & IXON) {
3397 cor2 |= COR2_TXIBE;
3398 cor3 |= COR3_SCD12;
3399 if (tiosp->c_iflag & IXANY)
3400 cor2 |= COR2_IXM;
3401 }
3402
3403 if (tiosp->c_cflag & CRTSCTS) {
3404 cor2 |= COR2_CTSAE;
3405 mcor1 |= FIFO_RTSTHRESHOLD;
3406 }
3407
3408/*
3409 * All cd1400 register values calculated so go through and set
3410 * them all up.
3411 */
3412
3413#ifdef DEBUG
3414 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3415 portp->portnr, portp->panelnr, portp->brdnr);
3416 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3417 cor1, cor2, cor3, cor4, cor5);
3418 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3419 mcor1, mcor2, rtpr, sreron, sreroff);
3420 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3421 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3422 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3423 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3424#endif
3425
3426 save_flags(flags);
3427 cli();
3428 BRDENABLE(portp->brdnr, portp->pagenr);
3429 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3430 srer = stl_cd1400getreg(portp, SRER);
3431 stl_cd1400setreg(portp, SRER, 0);
3432 if (stl_cd1400updatereg(portp, COR1, cor1))
3433 ccr = 1;
3434 if (stl_cd1400updatereg(portp, COR2, cor2))
3435 ccr = 1;
3436 if (stl_cd1400updatereg(portp, COR3, cor3))
3437 ccr = 1;
3438 if (ccr) {
3439 stl_cd1400ccrwait(portp);
3440 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3441 }
3442 stl_cd1400setreg(portp, COR4, cor4);
3443 stl_cd1400setreg(portp, COR5, cor5);
3444 stl_cd1400setreg(portp, MCOR1, mcor1);
3445 stl_cd1400setreg(portp, MCOR2, mcor2);
3446 if (baudrate > 0) {
3447 stl_cd1400setreg(portp, TCOR, clk);
3448 stl_cd1400setreg(portp, TBPR, div);
3449 stl_cd1400setreg(portp, RCOR, clk);
3450 stl_cd1400setreg(portp, RBPR, div);
3451 }
3452 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3453 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3454 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3455 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3456 stl_cd1400setreg(portp, RTPR, rtpr);
3457 mcor1 = stl_cd1400getreg(portp, MSVR1);
3458 if (mcor1 & MSVR1_DCD)
3459 portp->sigs |= TIOCM_CD;
3460 else
3461 portp->sigs &= ~TIOCM_CD;
3462 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3463 BRDDISABLE(portp->brdnr);
3464 restore_flags(flags);
3465}
3466
3467/*****************************************************************************/
3468
3469/*
3470 * Set the state of the DTR and RTS signals.
3471 */
3472
3473static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3474{
3475 unsigned char msvr1, msvr2;
3476 unsigned long flags;
3477
3478#ifdef DEBUG
3479 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3480 (int) portp, dtr, rts);
3481#endif
3482
3483 msvr1 = 0;
3484 msvr2 = 0;
3485 if (dtr > 0)
3486 msvr1 = MSVR1_DTR;
3487 if (rts > 0)
3488 msvr2 = MSVR2_RTS;
3489
3490 save_flags(flags);
3491 cli();
3492 BRDENABLE(portp->brdnr, portp->pagenr);
3493 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3494 if (rts >= 0)
3495 stl_cd1400setreg(portp, MSVR2, msvr2);
3496 if (dtr >= 0)
3497 stl_cd1400setreg(portp, MSVR1, msvr1);
3498 BRDDISABLE(portp->brdnr);
3499 restore_flags(flags);
3500}
3501
3502/*****************************************************************************/
3503
3504/*
3505 * Return the state of the signals.
3506 */
3507
3508static int stl_cd1400getsignals(stlport_t *portp)
3509{
3510 unsigned char msvr1, msvr2;
3511 unsigned long flags;
3512 int sigs;
3513
3514#ifdef DEBUG
3515 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3516#endif
3517
3518 save_flags(flags);
3519 cli();
3520 BRDENABLE(portp->brdnr, portp->pagenr);
3521 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3522 msvr1 = stl_cd1400getreg(portp, MSVR1);
3523 msvr2 = stl_cd1400getreg(portp, MSVR2);
3524 BRDDISABLE(portp->brdnr);
3525 restore_flags(flags);
3526
3527 sigs = 0;
3528 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3529 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3530 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3531 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3532#if 0
3533 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3534 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3535#else
3536 sigs |= TIOCM_DSR;
3537#endif
014c2544 3538 return sigs;
1da177e4
LT
3539}
3540
3541/*****************************************************************************/
3542
3543/*
3544 * Enable/Disable the Transmitter and/or Receiver.
3545 */
3546
3547static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3548{
3549 unsigned char ccr;
3550 unsigned long flags;
3551
3552#ifdef DEBUG
3553 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3554 (int) portp, rx, tx);
3555#endif
3556 ccr = 0;
3557
3558 if (tx == 0)
3559 ccr |= CCR_TXDISABLE;
3560 else if (tx > 0)
3561 ccr |= CCR_TXENABLE;
3562 if (rx == 0)
3563 ccr |= CCR_RXDISABLE;
3564 else if (rx > 0)
3565 ccr |= CCR_RXENABLE;
3566
3567 save_flags(flags);
3568 cli();
3569 BRDENABLE(portp->brdnr, portp->pagenr);
3570 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3571 stl_cd1400ccrwait(portp);
3572 stl_cd1400setreg(portp, CCR, ccr);
3573 stl_cd1400ccrwait(portp);
3574 BRDDISABLE(portp->brdnr);
3575 restore_flags(flags);
3576}
3577
3578/*****************************************************************************/
3579
3580/*
3581 * Start/stop the Transmitter and/or Receiver.
3582 */
3583
3584static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3585{
3586 unsigned char sreron, sreroff;
3587 unsigned long flags;
3588
3589#ifdef DEBUG
3590 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3591 (int) portp, rx, tx);
3592#endif
3593
3594 sreron = 0;
3595 sreroff = 0;
3596 if (tx == 0)
3597 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3598 else if (tx == 1)
3599 sreron |= SRER_TXDATA;
3600 else if (tx >= 2)
3601 sreron |= SRER_TXEMPTY;
3602 if (rx == 0)
3603 sreroff |= SRER_RXDATA;
3604 else if (rx > 0)
3605 sreron |= SRER_RXDATA;
3606
3607 save_flags(flags);
3608 cli();
3609 BRDENABLE(portp->brdnr, portp->pagenr);
3610 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3611 stl_cd1400setreg(portp, SRER,
3612 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3613 BRDDISABLE(portp->brdnr);
3614 if (tx > 0)
3615 set_bit(ASYI_TXBUSY, &portp->istate);
3616 restore_flags(flags);
3617}
3618
3619/*****************************************************************************/
3620
3621/*
3622 * Disable all interrupts from this port.
3623 */
3624
3625static void stl_cd1400disableintrs(stlport_t *portp)
3626{
3627 unsigned long flags;
3628
3629#ifdef DEBUG
3630 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3631#endif
3632 save_flags(flags);
3633 cli();
3634 BRDENABLE(portp->brdnr, portp->pagenr);
3635 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3636 stl_cd1400setreg(portp, SRER, 0);
3637 BRDDISABLE(portp->brdnr);
3638 restore_flags(flags);
3639}
3640
3641/*****************************************************************************/
3642
3643static void stl_cd1400sendbreak(stlport_t *portp, int len)
3644{
3645 unsigned long flags;
3646
3647#ifdef DEBUG
3648 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3649#endif
3650
3651 save_flags(flags);
3652 cli();
3653 BRDENABLE(portp->brdnr, portp->pagenr);
3654 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3655 stl_cd1400setreg(portp, SRER,
3656 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3657 SRER_TXEMPTY));
3658 BRDDISABLE(portp->brdnr);
3659 portp->brklen = len;
3660 if (len == 1)
3661 portp->stats.txbreaks++;
3662 restore_flags(flags);
3663}
3664
3665/*****************************************************************************/
3666
3667/*
3668 * Take flow control actions...
3669 */
3670
3671static void stl_cd1400flowctrl(stlport_t *portp, int state)
3672{
3673 struct tty_struct *tty;
3674 unsigned long flags;
3675
3676#ifdef DEBUG
3677 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3678#endif
3679
3680 if (portp == (stlport_t *) NULL)
3681 return;
3682 tty = portp->tty;
3683 if (tty == (struct tty_struct *) NULL)
3684 return;
3685
3686 save_flags(flags);
3687 cli();
3688 BRDENABLE(portp->brdnr, portp->pagenr);
3689 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3690
3691 if (state) {
3692 if (tty->termios->c_iflag & IXOFF) {
3693 stl_cd1400ccrwait(portp);
3694 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3695 portp->stats.rxxon++;
3696 stl_cd1400ccrwait(portp);
3697 }
3698/*
3699 * Question: should we return RTS to what it was before? It may
3700 * have been set by an ioctl... Suppose not, since if you have
3701 * hardware flow control set then it is pretty silly to go and
3702 * set the RTS line by hand.
3703 */
3704 if (tty->termios->c_cflag & CRTSCTS) {
3705 stl_cd1400setreg(portp, MCOR1,
3706 (stl_cd1400getreg(portp, MCOR1) |
3707 FIFO_RTSTHRESHOLD));
3708 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3709 portp->stats.rxrtson++;
3710 }
3711 } else {
3712 if (tty->termios->c_iflag & IXOFF) {
3713 stl_cd1400ccrwait(portp);
3714 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3715 portp->stats.rxxoff++;
3716 stl_cd1400ccrwait(portp);
3717 }
3718 if (tty->termios->c_cflag & CRTSCTS) {
3719 stl_cd1400setreg(portp, MCOR1,
3720 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3721 stl_cd1400setreg(portp, MSVR2, 0);
3722 portp->stats.rxrtsoff++;
3723 }
3724 }
3725
3726 BRDDISABLE(portp->brdnr);
3727 restore_flags(flags);
3728}
3729
3730/*****************************************************************************/
3731
3732/*
3733 * Send a flow control character...
3734 */
3735
3736static void stl_cd1400sendflow(stlport_t *portp, int state)
3737{
3738 struct tty_struct *tty;
3739 unsigned long flags;
3740
3741#ifdef DEBUG
3742 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3743#endif
3744
3745 if (portp == (stlport_t *) NULL)
3746 return;
3747 tty = portp->tty;
3748 if (tty == (struct tty_struct *) NULL)
3749 return;
3750
3751 save_flags(flags);
3752 cli();
3753 BRDENABLE(portp->brdnr, portp->pagenr);
3754 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3755 if (state) {
3756 stl_cd1400ccrwait(portp);
3757 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3758 portp->stats.rxxon++;
3759 stl_cd1400ccrwait(portp);
3760 } else {
3761 stl_cd1400ccrwait(portp);
3762 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3763 portp->stats.rxxoff++;
3764 stl_cd1400ccrwait(portp);
3765 }
3766 BRDDISABLE(portp->brdnr);
3767 restore_flags(flags);
3768}
3769
3770/*****************************************************************************/
3771
3772static void stl_cd1400flush(stlport_t *portp)
3773{
3774 unsigned long flags;
3775
3776#ifdef DEBUG
3777 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3778#endif
3779
3780 if (portp == (stlport_t *) NULL)
3781 return;
3782
3783 save_flags(flags);
3784 cli();
3785 BRDENABLE(portp->brdnr, portp->pagenr);
3786 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3787 stl_cd1400ccrwait(portp);
3788 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3789 stl_cd1400ccrwait(portp);
3790 portp->tx.tail = portp->tx.head;
3791 BRDDISABLE(portp->brdnr);
3792 restore_flags(flags);
3793}
3794
3795/*****************************************************************************/
3796
3797/*
3798 * Return the current state of data flow on this port. This is only
3799 * really interresting when determining if data has fully completed
3800 * transmission or not... This is easy for the cd1400, it accurately
3801 * maintains the busy port flag.
3802 */
3803
3804static int stl_cd1400datastate(stlport_t *portp)
3805{
3806#ifdef DEBUG
3807 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3808#endif
3809
3810 if (portp == (stlport_t *) NULL)
014c2544 3811 return 0;
1da177e4 3812
014c2544 3813 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
1da177e4
LT
3814}
3815
3816/*****************************************************************************/
3817
3818/*
3819 * Interrupt service routine for cd1400 EasyIO boards.
3820 */
3821
3822static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3823{
3824 unsigned char svrtype;
3825
3826#ifdef DEBUG
3827 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3828 (int) panelp, iobase);
3829#endif
3830
3831 outb(SVRR, iobase);
3832 svrtype = inb(iobase + EREG_DATA);
3833 if (panelp->nrports > 4) {
3834 outb((SVRR + 0x80), iobase);
3835 svrtype |= inb(iobase + EREG_DATA);
3836 }
3837
3838 if (svrtype & SVRR_RX)
3839 stl_cd1400rxisr(panelp, iobase);
3840 else if (svrtype & SVRR_TX)
3841 stl_cd1400txisr(panelp, iobase);
3842 else if (svrtype & SVRR_MDM)
3843 stl_cd1400mdmisr(panelp, iobase);
3844}
3845
3846/*****************************************************************************/
3847
3848/*
3849 * Interrupt service routine for cd1400 panels.
3850 */
3851
3852static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3853{
3854 unsigned char svrtype;
3855
3856#ifdef DEBUG
3857 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3858 iobase);
3859#endif
3860
3861 outb(SVRR, iobase);
3862 svrtype = inb(iobase + EREG_DATA);
3863 outb((SVRR + 0x80), iobase);
3864 svrtype |= inb(iobase + EREG_DATA);
3865 if (svrtype & SVRR_RX)
3866 stl_cd1400rxisr(panelp, iobase);
3867 else if (svrtype & SVRR_TX)
3868 stl_cd1400txisr(panelp, iobase);
3869 else if (svrtype & SVRR_MDM)
3870 stl_cd1400mdmisr(panelp, iobase);
3871}
3872
3873
3874/*****************************************************************************/
3875
3876/*
3877 * Unfortunately we need to handle breaks in the TX data stream, since
3878 * this is the only way to generate them on the cd1400.
3879 */
3880
3881static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3882{
3883 if (portp->brklen == 1) {
3884 outb((COR2 + portp->uartaddr), ioaddr);
3885 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3886 (ioaddr + EREG_DATA));
3887 outb((TDR + portp->uartaddr), ioaddr);
3888 outb(ETC_CMD, (ioaddr + EREG_DATA));
3889 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3890 outb((SRER + portp->uartaddr), ioaddr);
3891 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3892 (ioaddr + EREG_DATA));
014c2544 3893 return 1;
1da177e4
LT
3894 } else if (portp->brklen > 1) {
3895 outb((TDR + portp->uartaddr), ioaddr);
3896 outb(ETC_CMD, (ioaddr + EREG_DATA));
3897 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3898 portp->brklen = -1;
014c2544 3899 return 1;
1da177e4
LT
3900 } else {
3901 outb((COR2 + portp->uartaddr), ioaddr);
3902 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3903 (ioaddr + EREG_DATA));
3904 portp->brklen = 0;
3905 }
014c2544 3906 return 0;
1da177e4
LT
3907}
3908
3909/*****************************************************************************/
3910
3911/*
3912 * Transmit interrupt handler. This has gotta be fast! Handling TX
3913 * chars is pretty simple, stuff as many as possible from the TX buffer
3914 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3915 * are embedded as commands in the data stream. Oh no, had to use a goto!
3916 * This could be optimized more, will do when I get time...
3917 * In practice it is possible that interrupts are enabled but that the
3918 * port has been hung up. Need to handle not having any TX buffer here,
3919 * this is done by using the side effect that head and tail will also
3920 * be NULL if the buffer has been freed.
3921 */
3922
3923static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
3924{
3925 stlport_t *portp;
3926 int len, stlen;
3927 char *head, *tail;
3928 unsigned char ioack, srer;
3929
3930#ifdef DEBUG
3931 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3932#endif
3933
3934 ioack = inb(ioaddr + EREG_TXACK);
3935 if (((ioack & panelp->ackmask) != 0) ||
3936 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3937 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3938 return;
3939 }
3940 portp = panelp->ports[(ioack >> 3)];
3941
3942/*
3943 * Unfortunately we need to handle breaks in the data stream, since
3944 * this is the only way to generate them on the cd1400. Do it now if
3945 * a break is to be sent.
3946 */
3947 if (portp->brklen != 0)
3948 if (stl_cd1400breakisr(portp, ioaddr))
3949 goto stl_txalldone;
3950
3951 head = portp->tx.head;
3952 tail = portp->tx.tail;
3953 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3954 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3955 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3956 set_bit(ASYI_TXLOW, &portp->istate);
3957 schedule_work(&portp->tqueue);
3958 }
3959
3960 if (len == 0) {
3961 outb((SRER + portp->uartaddr), ioaddr);
3962 srer = inb(ioaddr + EREG_DATA);
3963 if (srer & SRER_TXDATA) {
3964 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3965 } else {
3966 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3967 clear_bit(ASYI_TXBUSY, &portp->istate);
3968 }
3969 outb(srer, (ioaddr + EREG_DATA));
3970 } else {
3971 len = MIN(len, CD1400_TXFIFOSIZE);
3972 portp->stats.txtotal += len;
3973 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3974 outb((TDR + portp->uartaddr), ioaddr);
3975 outsb((ioaddr + EREG_DATA), tail, stlen);
3976 len -= stlen;
3977 tail += stlen;
3978 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3979 tail = portp->tx.buf;
3980 if (len > 0) {
3981 outsb((ioaddr + EREG_DATA), tail, len);
3982 tail += len;
3983 }
3984 portp->tx.tail = tail;
3985 }
3986
3987stl_txalldone:
3988 outb((EOSRR + portp->uartaddr), ioaddr);
3989 outb(0, (ioaddr + EREG_DATA));
3990}
3991
3992/*****************************************************************************/
3993
3994/*
3995 * Receive character interrupt handler. Determine if we have good chars
3996 * or bad chars and then process appropriately. Good chars are easy
3997 * just shove the lot into the RX buffer and set all status byte to 0.
3998 * If a bad RX char then process as required. This routine needs to be
3999 * fast! In practice it is possible that we get an interrupt on a port
4000 * that is closed. This can happen on hangups - since they completely
4001 * shutdown a port not in user context. Need to handle this case.
4002 */
4003
4004static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4005{
4006 stlport_t *portp;
4007 struct tty_struct *tty;
4008 unsigned int ioack, len, buflen;
4009 unsigned char status;
4010 char ch;
4011
4012#ifdef DEBUG
4013 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4014#endif
4015
4016 ioack = inb(ioaddr + EREG_RXACK);
4017 if ((ioack & panelp->ackmask) != 0) {
4018 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4019 return;
4020 }
4021 portp = panelp->ports[(ioack >> 3)];
4022 tty = portp->tty;
4023
4024 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4025 outb((RDCR + portp->uartaddr), ioaddr);
4026 len = inb(ioaddr + EREG_DATA);
33f0f88f 4027 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
1da177e4
LT
4028 len = MIN(len, sizeof(stl_unwanted));
4029 outb((RDSR + portp->uartaddr), ioaddr);
4030 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4031 portp->stats.rxlost += len;
4032 portp->stats.rxtotal += len;
4033 } else {
4034 len = MIN(len, buflen);
4035 if (len > 0) {
33f0f88f 4036 unsigned char *ptr;
1da177e4 4037 outb((RDSR + portp->uartaddr), ioaddr);
33f0f88f
AC
4038 tty_prepare_flip_string(tty, &ptr, len);
4039 insb((ioaddr + EREG_DATA), ptr, len);
1da177e4
LT
4040 tty_schedule_flip(tty);
4041 portp->stats.rxtotal += len;
4042 }
4043 }
4044 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4045 outb((RDSR + portp->uartaddr), ioaddr);
4046 status = inb(ioaddr + EREG_DATA);
4047 ch = inb(ioaddr + EREG_DATA);
4048 if (status & ST_PARITY)
4049 portp->stats.rxparity++;
4050 if (status & ST_FRAMING)
4051 portp->stats.rxframing++;
4052 if (status & ST_OVERRUN)
4053 portp->stats.rxoverrun++;
4054 if (status & ST_BREAK)
4055 portp->stats.rxbreaks++;
4056 if (status & ST_SCHARMASK) {
4057 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4058 portp->stats.txxon++;
4059 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4060 portp->stats.txxoff++;
4061 goto stl_rxalldone;
4062 }
33f0f88f 4063 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
1da177e4
LT
4064 if (portp->rxmarkmsk & status) {
4065 if (status & ST_BREAK) {
4066 status = TTY_BREAK;
4067 if (portp->flags & ASYNC_SAK) {
4068 do_SAK(tty);
4069 BRDENABLE(portp->brdnr, portp->pagenr);
4070 }
4071 } else if (status & ST_PARITY) {
4072 status = TTY_PARITY;
4073 } else if (status & ST_FRAMING) {
4074 status = TTY_FRAME;
4075 } else if(status & ST_OVERRUN) {
4076 status = TTY_OVERRUN;
4077 } else {
4078 status = 0;
4079 }
4080 } else {
4081 status = 0;
4082 }
33f0f88f
AC
4083 tty_insert_flip_char(tty, ch, status);
4084 tty_schedule_flip(tty);
1da177e4
LT
4085 }
4086 } else {
4087 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4088 return;
4089 }
4090
4091stl_rxalldone:
4092 outb((EOSRR + portp->uartaddr), ioaddr);
4093 outb(0, (ioaddr + EREG_DATA));
4094}
4095
4096/*****************************************************************************/
4097
4098/*
4099 * Modem interrupt handler. The is called when the modem signal line
4100 * (DCD) has changed state. Leave most of the work to the off-level
4101 * processing routine.
4102 */
4103
4104static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4105{
4106 stlport_t *portp;
4107 unsigned int ioack;
4108 unsigned char misr;
4109
4110#ifdef DEBUG
4111 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4112#endif
4113
4114 ioack = inb(ioaddr + EREG_MDACK);
4115 if (((ioack & panelp->ackmask) != 0) ||
4116 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4117 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4118 return;
4119 }
4120 portp = panelp->ports[(ioack >> 3)];
4121
4122 outb((MISR + portp->uartaddr), ioaddr);
4123 misr = inb(ioaddr + EREG_DATA);
4124 if (misr & MISR_DCD) {
4125 set_bit(ASYI_DCDCHANGE, &portp->istate);
4126 schedule_work(&portp->tqueue);
4127 portp->stats.modem++;
4128 }
4129
4130 outb((EOSRR + portp->uartaddr), ioaddr);
4131 outb(0, (ioaddr + EREG_DATA));
4132}
4133
4134/*****************************************************************************/
4135/* SC26198 HARDWARE FUNCTIONS */
4136/*****************************************************************************/
4137
4138/*
4139 * These functions get/set/update the registers of the sc26198 UARTs.
4140 * Access to the sc26198 registers is via an address/data io port pair.
4141 * (Maybe should make this inline...)
4142 */
4143
4144static int stl_sc26198getreg(stlport_t *portp, int regnr)
4145{
4146 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
014c2544 4147 return inb(portp->ioaddr + XP_DATA);
1da177e4
LT
4148}
4149
4150static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4151{
4152 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4153 outb(value, (portp->ioaddr + XP_DATA));
4154}
4155
4156static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4157{
4158 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4159 if (inb(portp->ioaddr + XP_DATA) != value) {
4160 outb(value, (portp->ioaddr + XP_DATA));
014c2544 4161 return 1;
1da177e4 4162 }
014c2544 4163 return 0;
1da177e4
LT
4164}
4165
4166/*****************************************************************************/
4167
4168/*
4169 * Functions to get and set the sc26198 global registers.
4170 */
4171
4172static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4173{
4174 outb(regnr, (portp->ioaddr + XP_ADDR));
014c2544 4175 return inb(portp->ioaddr + XP_DATA);
1da177e4
LT
4176}
4177
4178#if 0
4179static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4180{
4181 outb(regnr, (portp->ioaddr + XP_ADDR));
4182 outb(value, (portp->ioaddr + XP_DATA));
4183}
4184#endif
4185
4186/*****************************************************************************/
4187
4188/*
4189 * Inbitialize the UARTs in a panel. We don't care what sort of board
4190 * these ports are on - since the port io registers are almost
4191 * identical when dealing with ports.
4192 */
4193
4194static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4195{
4196 int chipmask, i;
4197 int nrchips, ioaddr;
4198
4199#ifdef DEBUG
4200 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4201 (int) brdp, (int) panelp);
4202#endif
4203
4204 BRDENABLE(panelp->brdnr, panelp->pagenr);
4205
4206/*
4207 * Check that each chip is present and started up OK.
4208 */
4209 chipmask = 0;
4210 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4211 if (brdp->brdtype == BRD_ECHPCI)
4212 outb(panelp->pagenr, brdp->ioctrl);
4213
4214 for (i = 0; (i < nrchips); i++) {
4215 ioaddr = panelp->iobase + (i * 4);
4216 outb(SCCR, (ioaddr + XP_ADDR));
4217 outb(CR_RESETALL, (ioaddr + XP_DATA));
4218 outb(TSTR, (ioaddr + XP_ADDR));
4219 if (inb(ioaddr + XP_DATA) != 0) {
4220 printk("STALLION: sc26198 not responding, "
4221 "brd=%d panel=%d chip=%d\n",
4222 panelp->brdnr, panelp->panelnr, i);
4223 continue;
4224 }
4225 chipmask |= (0x1 << i);
4226 outb(GCCR, (ioaddr + XP_ADDR));
4227 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4228 outb(WDTRCR, (ioaddr + XP_ADDR));
4229 outb(0xff, (ioaddr + XP_DATA));
4230 }
4231
4232 BRDDISABLE(panelp->brdnr);
014c2544 4233 return chipmask;
1da177e4
LT
4234}
4235
4236/*****************************************************************************/
4237
4238/*
4239 * Initialize hardware specific port registers.
4240 */
4241
4242static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4243{
4244#ifdef DEBUG
4245 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4246 (int) brdp, (int) panelp, (int) portp);
4247#endif
4248
4249 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4250 (portp == (stlport_t *) NULL))
4251 return;
4252
4253 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4254 portp->uartaddr = (portp->portnr & 0x07) << 4;
4255 portp->pagenr = panelp->pagenr;
4256 portp->hwid = 0x1;
4257
4258 BRDENABLE(portp->brdnr, portp->pagenr);
4259 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4260 BRDDISABLE(portp->brdnr);
4261}
4262
4263/*****************************************************************************/
4264
4265/*
4266 * Set up the sc26198 registers for a port based on the termios port
4267 * settings.
4268 */
4269
4270static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4271{
4272 stlbrd_t *brdp;
4273 unsigned long flags;
4274 unsigned int baudrate;
4275 unsigned char mr0, mr1, mr2, clk;
4276 unsigned char imron, imroff, iopr, ipr;
4277
4278 mr0 = 0;
4279 mr1 = 0;
4280 mr2 = 0;
4281 clk = 0;
4282 iopr = 0;
4283 imron = 0;
4284 imroff = 0;
4285
4286 brdp = stl_brds[portp->brdnr];
4287 if (brdp == (stlbrd_t *) NULL)
4288 return;
4289
4290/*
4291 * Set up the RX char ignore mask with those RX error types we
4292 * can ignore.
4293 */
4294 portp->rxignoremsk = 0;
4295 if (tiosp->c_iflag & IGNPAR)
4296 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4297 SR_RXOVERRUN);
4298 if (tiosp->c_iflag & IGNBRK)
4299 portp->rxignoremsk |= SR_RXBREAK;
4300
4301 portp->rxmarkmsk = SR_RXOVERRUN;
4302 if (tiosp->c_iflag & (INPCK | PARMRK))
4303 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4304 if (tiosp->c_iflag & BRKINT)
4305 portp->rxmarkmsk |= SR_RXBREAK;
4306
4307/*
4308 * Go through the char size, parity and stop bits and set all the
4309 * option register appropriately.
4310 */
4311 switch (tiosp->c_cflag & CSIZE) {
4312 case CS5:
4313 mr1 |= MR1_CS5;
4314 break;
4315 case CS6:
4316 mr1 |= MR1_CS6;
4317 break;
4318 case CS7:
4319 mr1 |= MR1_CS7;
4320 break;
4321 default:
4322 mr1 |= MR1_CS8;
4323 break;
4324 }
4325
4326 if (tiosp->c_cflag & CSTOPB)
4327 mr2 |= MR2_STOP2;
4328 else
4329 mr2 |= MR2_STOP1;
4330
4331 if (tiosp->c_cflag & PARENB) {
4332 if (tiosp->c_cflag & PARODD)
4333 mr1 |= (MR1_PARENB | MR1_PARODD);
4334 else
4335 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4336 } else {
4337 mr1 |= MR1_PARNONE;
4338 }
4339
4340 mr1 |= MR1_ERRBLOCK;
4341
4342/*
4343 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4344 * space for hardware flow control and the like. This should be set to
4345 * VMIN.
4346 */
4347 mr2 |= MR2_RXFIFOHALF;
4348
4349/*
4350 * Calculate the baud rate timers. For now we will just assume that
4351 * the input and output baud are the same. The sc26198 has a fixed
4352 * baud rate table, so only discrete baud rates possible.
4353 */
4354 baudrate = tiosp->c_cflag & CBAUD;
4355 if (baudrate & CBAUDEX) {
4356 baudrate &= ~CBAUDEX;
4357 if ((baudrate < 1) || (baudrate > 4))
4358 tiosp->c_cflag &= ~CBAUDEX;
4359 else
4360 baudrate += 15;
4361 }
4362 baudrate = stl_baudrates[baudrate];
4363 if ((tiosp->c_cflag & CBAUD) == B38400) {
4364 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4365 baudrate = 57600;
4366 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4367 baudrate = 115200;
4368 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4369 baudrate = 230400;
4370 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4371 baudrate = 460800;
4372 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4373 baudrate = (portp->baud_base / portp->custom_divisor);
4374 }
4375 if (baudrate > STL_SC26198MAXBAUD)
4376 baudrate = STL_SC26198MAXBAUD;
4377
4378 if (baudrate > 0) {
4379 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4380 if (baudrate <= sc26198_baudtable[clk])
4381 break;
4382 }
4383 }
4384
4385/*
4386 * Check what form of modem signaling is required and set it up.
4387 */
4388 if (tiosp->c_cflag & CLOCAL) {
4389 portp->flags &= ~ASYNC_CHECK_CD;
4390 } else {
4391 iopr |= IOPR_DCDCOS;
4392 imron |= IR_IOPORT;
4393 portp->flags |= ASYNC_CHECK_CD;
4394 }
4395
4396/*
4397 * Setup sc26198 enhanced modes if we can. In particular we want to
4398 * handle as much of the flow control as possible automatically. As
4399 * well as saving a few CPU cycles it will also greatly improve flow
4400 * control reliability.
4401 */
4402 if (tiosp->c_iflag & IXON) {
4403 mr0 |= MR0_SWFTX | MR0_SWFT;
4404 imron |= IR_XONXOFF;
4405 } else {
4406 imroff |= IR_XONXOFF;
4407 }
4408 if (tiosp->c_iflag & IXOFF)
4409 mr0 |= MR0_SWFRX;
4410
4411 if (tiosp->c_cflag & CRTSCTS) {
4412 mr2 |= MR2_AUTOCTS;
4413 mr1 |= MR1_AUTORTS;
4414 }
4415
4416/*
4417 * All sc26198 register values calculated so go through and set
4418 * them all up.
4419 */
4420
4421#ifdef DEBUG
4422 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4423 portp->portnr, portp->panelnr, portp->brdnr);
4424 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4425 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4426 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4427 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4428 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4429#endif
4430
4431 save_flags(flags);
4432 cli();
4433 BRDENABLE(portp->brdnr, portp->pagenr);
4434 stl_sc26198setreg(portp, IMR, 0);
4435 stl_sc26198updatereg(portp, MR0, mr0);
4436 stl_sc26198updatereg(portp, MR1, mr1);
4437 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4438 stl_sc26198updatereg(portp, MR2, mr2);
4439 stl_sc26198updatereg(portp, IOPIOR,
4440 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4441
4442 if (baudrate > 0) {
4443 stl_sc26198setreg(portp, TXCSR, clk);
4444 stl_sc26198setreg(portp, RXCSR, clk);
4445 }
4446
4447 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4448 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4449
4450 ipr = stl_sc26198getreg(portp, IPR);
4451 if (ipr & IPR_DCD)
4452 portp->sigs &= ~TIOCM_CD;
4453 else
4454 portp->sigs |= TIOCM_CD;
4455
4456 portp->imr = (portp->imr & ~imroff) | imron;
4457 stl_sc26198setreg(portp, IMR, portp->imr);
4458 BRDDISABLE(portp->brdnr);
4459 restore_flags(flags);
4460}
4461
4462/*****************************************************************************/
4463
4464/*
4465 * Set the state of the DTR and RTS signals.
4466 */
4467
4468static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4469{
4470 unsigned char iopioron, iopioroff;
4471 unsigned long flags;
4472
4473#ifdef DEBUG
4474 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4475 (int) portp, dtr, rts);
4476#endif
4477
4478 iopioron = 0;
4479 iopioroff = 0;
4480 if (dtr == 0)
4481 iopioroff |= IPR_DTR;
4482 else if (dtr > 0)
4483 iopioron |= IPR_DTR;
4484 if (rts == 0)
4485 iopioroff |= IPR_RTS;
4486 else if (rts > 0)
4487 iopioron |= IPR_RTS;
4488
4489 save_flags(flags);
4490 cli();
4491 BRDENABLE(portp->brdnr, portp->pagenr);
4492 stl_sc26198setreg(portp, IOPIOR,
4493 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4494 BRDDISABLE(portp->brdnr);
4495 restore_flags(flags);
4496}
4497
4498/*****************************************************************************/
4499
4500/*
4501 * Return the state of the signals.
4502 */
4503
4504static int stl_sc26198getsignals(stlport_t *portp)
4505{
4506 unsigned char ipr;
4507 unsigned long flags;
4508 int sigs;
4509
4510#ifdef DEBUG
4511 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4512#endif
4513
4514 save_flags(flags);
4515 cli();
4516 BRDENABLE(portp->brdnr, portp->pagenr);
4517 ipr = stl_sc26198getreg(portp, IPR);
4518 BRDDISABLE(portp->brdnr);
4519 restore_flags(flags);
4520
4521 sigs = 0;
4522 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4523 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4524 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4525 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4526 sigs |= TIOCM_DSR;
014c2544 4527 return sigs;
1da177e4
LT
4528}
4529
4530/*****************************************************************************/
4531
4532/*
4533 * Enable/Disable the Transmitter and/or Receiver.
4534 */
4535
4536static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4537{
4538 unsigned char ccr;
4539 unsigned long flags;
4540
4541#ifdef DEBUG
4542 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4543 (int) portp, rx, tx);
4544#endif
4545
4546 ccr = portp->crenable;
4547 if (tx == 0)
4548 ccr &= ~CR_TXENABLE;
4549 else if (tx > 0)
4550 ccr |= CR_TXENABLE;
4551 if (rx == 0)
4552 ccr &= ~CR_RXENABLE;
4553 else if (rx > 0)
4554 ccr |= CR_RXENABLE;
4555
4556 save_flags(flags);
4557 cli();
4558 BRDENABLE(portp->brdnr, portp->pagenr);
4559 stl_sc26198setreg(portp, SCCR, ccr);
4560 BRDDISABLE(portp->brdnr);
4561 portp->crenable = ccr;
4562 restore_flags(flags);
4563}
4564
4565/*****************************************************************************/
4566
4567/*
4568 * Start/stop the Transmitter and/or Receiver.
4569 */
4570
4571static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4572{
4573 unsigned char imr;
4574 unsigned long flags;
4575
4576#ifdef DEBUG
4577 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4578 (int) portp, rx, tx);
4579#endif
4580
4581 imr = portp->imr;
4582 if (tx == 0)
4583 imr &= ~IR_TXRDY;
4584 else if (tx == 1)
4585 imr |= IR_TXRDY;
4586 if (rx == 0)
4587 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4588 else if (rx > 0)
4589 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4590
4591 save_flags(flags);
4592 cli();
4593 BRDENABLE(portp->brdnr, portp->pagenr);
4594 stl_sc26198setreg(portp, IMR, imr);
4595 BRDDISABLE(portp->brdnr);
4596 portp->imr = imr;
4597 if (tx > 0)
4598 set_bit(ASYI_TXBUSY, &portp->istate);
4599 restore_flags(flags);
4600}
4601
4602/*****************************************************************************/
4603
4604/*
4605 * Disable all interrupts from this port.
4606 */
4607
4608static void stl_sc26198disableintrs(stlport_t *portp)
4609{
4610 unsigned long flags;
4611
4612#ifdef DEBUG
4613 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4614#endif
4615
4616 save_flags(flags);
4617 cli();
4618 BRDENABLE(portp->brdnr, portp->pagenr);
4619 portp->imr = 0;
4620 stl_sc26198setreg(portp, IMR, 0);
4621 BRDDISABLE(portp->brdnr);
4622 restore_flags(flags);
4623}
4624
4625/*****************************************************************************/
4626
4627static void stl_sc26198sendbreak(stlport_t *portp, int len)
4628{
4629 unsigned long flags;
4630
4631#ifdef DEBUG
4632 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4633#endif
4634
4635 save_flags(flags);
4636 cli();
4637 BRDENABLE(portp->brdnr, portp->pagenr);
4638 if (len == 1) {
4639 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4640 portp->stats.txbreaks++;
4641 } else {
4642 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4643 }
4644 BRDDISABLE(portp->brdnr);
4645 restore_flags(flags);
4646}
4647
4648/*****************************************************************************/
4649
4650/*
4651 * Take flow control actions...
4652 */
4653
4654static void stl_sc26198flowctrl(stlport_t *portp, int state)
4655{
4656 struct tty_struct *tty;
4657 unsigned long flags;
4658 unsigned char mr0;
4659
4660#ifdef DEBUG
4661 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4662#endif
4663
4664 if (portp == (stlport_t *) NULL)
4665 return;
4666 tty = portp->tty;
4667 if (tty == (struct tty_struct *) NULL)
4668 return;
4669
4670 save_flags(flags);
4671 cli();
4672 BRDENABLE(portp->brdnr, portp->pagenr);
4673
4674 if (state) {
4675 if (tty->termios->c_iflag & IXOFF) {
4676 mr0 = stl_sc26198getreg(portp, MR0);
4677 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4678 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4679 mr0 |= MR0_SWFRX;
4680 portp->stats.rxxon++;
4681 stl_sc26198wait(portp);
4682 stl_sc26198setreg(portp, MR0, mr0);
4683 }
4684/*
4685 * Question: should we return RTS to what it was before? It may
4686 * have been set by an ioctl... Suppose not, since if you have
4687 * hardware flow control set then it is pretty silly to go and
4688 * set the RTS line by hand.
4689 */
4690 if (tty->termios->c_cflag & CRTSCTS) {
4691 stl_sc26198setreg(portp, MR1,
4692 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4693 stl_sc26198setreg(portp, IOPIOR,
4694 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4695 portp->stats.rxrtson++;
4696 }
4697 } else {
4698 if (tty->termios->c_iflag & IXOFF) {
4699 mr0 = stl_sc26198getreg(portp, MR0);
4700 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4701 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4702 mr0 &= ~MR0_SWFRX;
4703 portp->stats.rxxoff++;
4704 stl_sc26198wait(portp);
4705 stl_sc26198setreg(portp, MR0, mr0);
4706 }
4707 if (tty->termios->c_cflag & CRTSCTS) {
4708 stl_sc26198setreg(portp, MR1,
4709 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4710 stl_sc26198setreg(portp, IOPIOR,
4711 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4712 portp->stats.rxrtsoff++;
4713 }
4714 }
4715
4716 BRDDISABLE(portp->brdnr);
4717 restore_flags(flags);
4718}
4719
4720/*****************************************************************************/
4721
4722/*
4723 * Send a flow control character.
4724 */
4725
4726static void stl_sc26198sendflow(stlport_t *portp, int state)
4727{
4728 struct tty_struct *tty;
4729 unsigned long flags;
4730 unsigned char mr0;
4731
4732#ifdef DEBUG
4733 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4734#endif
4735
4736 if (portp == (stlport_t *) NULL)
4737 return;
4738 tty = portp->tty;
4739 if (tty == (struct tty_struct *) NULL)
4740 return;
4741
4742 save_flags(flags);
4743 cli();
4744 BRDENABLE(portp->brdnr, portp->pagenr);
4745 if (state) {
4746 mr0 = stl_sc26198getreg(portp, MR0);
4747 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4748 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4749 mr0 |= MR0_SWFRX;
4750 portp->stats.rxxon++;
4751 stl_sc26198wait(portp);
4752 stl_sc26198setreg(portp, MR0, mr0);
4753 } else {
4754 mr0 = stl_sc26198getreg(portp, MR0);
4755 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4756 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4757 mr0 &= ~MR0_SWFRX;
4758 portp->stats.rxxoff++;
4759 stl_sc26198wait(portp);
4760 stl_sc26198setreg(portp, MR0, mr0);
4761 }
4762 BRDDISABLE(portp->brdnr);
4763 restore_flags(flags);
4764}
4765
4766/*****************************************************************************/
4767
4768static void stl_sc26198flush(stlport_t *portp)
4769{
4770 unsigned long flags;
4771
4772#ifdef DEBUG
4773 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4774#endif
4775
4776 if (portp == (stlport_t *) NULL)
4777 return;
4778
4779 save_flags(flags);
4780 cli();
4781 BRDENABLE(portp->brdnr, portp->pagenr);
4782 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4783 stl_sc26198setreg(portp, SCCR, portp->crenable);
4784 BRDDISABLE(portp->brdnr);
4785 portp->tx.tail = portp->tx.head;
4786 restore_flags(flags);
4787}
4788
4789/*****************************************************************************/
4790
4791/*
4792 * Return the current state of data flow on this port. This is only
4793 * really interresting when determining if data has fully completed
4794 * transmission or not... The sc26198 interrupt scheme cannot
4795 * determine when all data has actually drained, so we need to
4796 * check the port statusy register to be sure.
4797 */
4798
4799static int stl_sc26198datastate(stlport_t *portp)
4800{
4801 unsigned long flags;
4802 unsigned char sr;
4803
4804#ifdef DEBUG
4805 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4806#endif
4807
4808 if (portp == (stlport_t *) NULL)
014c2544 4809 return 0;
1da177e4 4810 if (test_bit(ASYI_TXBUSY, &portp->istate))
014c2544 4811 return 1;
1da177e4
LT
4812
4813 save_flags(flags);
4814 cli();
4815 BRDENABLE(portp->brdnr, portp->pagenr);
4816 sr = stl_sc26198getreg(portp, SR);
4817 BRDDISABLE(portp->brdnr);
4818 restore_flags(flags);
4819
014c2544 4820 return (sr & SR_TXEMPTY) ? 0 : 1;
1da177e4
LT
4821}
4822
4823/*****************************************************************************/
4824
4825/*
4826 * Delay for a small amount of time, to give the sc26198 a chance
4827 * to process a command...
4828 */
4829
4830static void stl_sc26198wait(stlport_t *portp)
4831{
4832 int i;
4833
4834#ifdef DEBUG
4835 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4836#endif
4837
4838 if (portp == (stlport_t *) NULL)
4839 return;
4840
4841 for (i = 0; (i < 20); i++)
4842 stl_sc26198getglobreg(portp, TSTR);
4843}
4844
4845/*****************************************************************************/
4846
4847/*
4848 * If we are TX flow controlled and in IXANY mode then we may
4849 * need to unflow control here. We gotta do this because of the
4850 * automatic flow control modes of the sc26198.
4851 */
4852
4853static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4854{
4855 unsigned char mr0;
4856
4857 mr0 = stl_sc26198getreg(portp, MR0);
4858 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4859 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4860 stl_sc26198wait(portp);
4861 stl_sc26198setreg(portp, MR0, mr0);
4862 clear_bit(ASYI_TXFLOWED, &portp->istate);
4863}
4864
4865/*****************************************************************************/
4866
4867/*
4868 * Interrupt service routine for sc26198 panels.
4869 */
4870
4871static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4872{
4873 stlport_t *portp;
4874 unsigned int iack;
4875
4876/*
4877 * Work around bug in sc26198 chip... Cannot have A6 address
4878 * line of UART high, else iack will be returned as 0.
4879 */
4880 outb(0, (iobase + 1));
4881
4882 iack = inb(iobase + XP_IACK);
4883 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4884
4885 if (iack & IVR_RXDATA)
4886 stl_sc26198rxisr(portp, iack);
4887 else if (iack & IVR_TXDATA)
4888 stl_sc26198txisr(portp);
4889 else
4890 stl_sc26198otherisr(portp, iack);
4891}
4892
4893/*****************************************************************************/
4894
4895/*
4896 * Transmit interrupt handler. This has gotta be fast! Handling TX
4897 * chars is pretty simple, stuff as many as possible from the TX buffer
4898 * into the sc26198 FIFO.
4899 * In practice it is possible that interrupts are enabled but that the
4900 * port has been hung up. Need to handle not having any TX buffer here,
4901 * this is done by using the side effect that head and tail will also
4902 * be NULL if the buffer has been freed.
4903 */
4904
4905static void stl_sc26198txisr(stlport_t *portp)
4906{
4907 unsigned int ioaddr;
4908 unsigned char mr0;
4909 int len, stlen;
4910 char *head, *tail;
4911
4912#ifdef DEBUG
4913 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
4914#endif
4915
4916 ioaddr = portp->ioaddr;
4917 head = portp->tx.head;
4918 tail = portp->tx.tail;
4919 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4920 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4921 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4922 set_bit(ASYI_TXLOW, &portp->istate);
4923 schedule_work(&portp->tqueue);
4924 }
4925
4926 if (len == 0) {
4927 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4928 mr0 = inb(ioaddr + XP_DATA);
4929 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4930 portp->imr &= ~IR_TXRDY;
4931 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4932 outb(portp->imr, (ioaddr + XP_DATA));
4933 clear_bit(ASYI_TXBUSY, &portp->istate);
4934 } else {
4935 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4936 outb(mr0, (ioaddr + XP_DATA));
4937 }
4938 } else {
4939 len = MIN(len, SC26198_TXFIFOSIZE);
4940 portp->stats.txtotal += len;
4941 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4942 outb(GTXFIFO, (ioaddr + XP_ADDR));
4943 outsb((ioaddr + XP_DATA), tail, stlen);
4944 len -= stlen;
4945 tail += stlen;
4946 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4947 tail = portp->tx.buf;
4948 if (len > 0) {
4949 outsb((ioaddr + XP_DATA), tail, len);
4950 tail += len;
4951 }
4952 portp->tx.tail = tail;
4953 }
4954}
4955
4956/*****************************************************************************/
4957
4958/*
4959 * Receive character interrupt handler. Determine if we have good chars
4960 * or bad chars and then process appropriately. Good chars are easy
4961 * just shove the lot into the RX buffer and set all status byte to 0.
4962 * If a bad RX char then process as required. This routine needs to be
4963 * fast! In practice it is possible that we get an interrupt on a port
4964 * that is closed. This can happen on hangups - since they completely
4965 * shutdown a port not in user context. Need to handle this case.
4966 */
4967
4968static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4969{
4970 struct tty_struct *tty;
4971 unsigned int len, buflen, ioaddr;
4972
4973#ifdef DEBUG
4974 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4975#endif
4976
4977 tty = portp->tty;
4978 ioaddr = portp->ioaddr;
4979 outb(GIBCR, (ioaddr + XP_ADDR));
4980 len = inb(ioaddr + XP_DATA) + 1;
4981
4982 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
33f0f88f 4983 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
1da177e4
LT
4984 len = MIN(len, sizeof(stl_unwanted));
4985 outb(GRXFIFO, (ioaddr + XP_ADDR));
4986 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4987 portp->stats.rxlost += len;
4988 portp->stats.rxtotal += len;
4989 } else {
4990 len = MIN(len, buflen);
4991 if (len > 0) {
33f0f88f 4992 unsigned char *ptr;
1da177e4 4993 outb(GRXFIFO, (ioaddr + XP_ADDR));
33f0f88f
AC
4994 tty_prepare_flip_string(tty, &ptr, len);
4995 insb((ioaddr + XP_DATA), ptr, len);
1da177e4
LT
4996 tty_schedule_flip(tty);
4997 portp->stats.rxtotal += len;
4998 }
4999 }
5000 } else {
5001 stl_sc26198rxbadchars(portp);
5002 }
5003
5004/*
5005 * If we are TX flow controlled and in IXANY mode then we may need
5006 * to unflow control here. We gotta do this because of the automatic
5007 * flow control modes of the sc26198.
5008 */
5009 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5010 if ((tty != (struct tty_struct *) NULL) &&
5011 (tty->termios != (struct termios *) NULL) &&
5012 (tty->termios->c_iflag & IXANY)) {
5013 stl_sc26198txunflow(portp, tty);
5014 }
5015 }
5016}
5017
5018/*****************************************************************************/
5019
5020/*
5021 * Process an RX bad character.
5022 */
5023
5024static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5025{
5026 struct tty_struct *tty;
5027 unsigned int ioaddr;
5028
5029 tty = portp->tty;
5030 ioaddr = portp->ioaddr;
5031
5032 if (status & SR_RXPARITY)
5033 portp->stats.rxparity++;
5034 if (status & SR_RXFRAMING)
5035 portp->stats.rxframing++;
5036 if (status & SR_RXOVERRUN)
5037 portp->stats.rxoverrun++;
5038 if (status & SR_RXBREAK)
5039 portp->stats.rxbreaks++;
5040
5041 if ((tty != (struct tty_struct *) NULL) &&
5042 ((portp->rxignoremsk & status) == 0)) {
5043 if (portp->rxmarkmsk & status) {
5044 if (status & SR_RXBREAK) {
5045 status = TTY_BREAK;
5046 if (portp->flags & ASYNC_SAK) {
5047 do_SAK(tty);
5048 BRDENABLE(portp->brdnr, portp->pagenr);
5049 }
5050 } else if (status & SR_RXPARITY) {
5051 status = TTY_PARITY;
5052 } else if (status & SR_RXFRAMING) {
5053 status = TTY_FRAME;
5054 } else if(status & SR_RXOVERRUN) {
5055 status = TTY_OVERRUN;
5056 } else {
5057 status = 0;
5058 }
5059 } else {
5060 status = 0;
5061 }
5062
33f0f88f
AC
5063 tty_insert_flip_char(tty, ch, status);
5064 tty_schedule_flip(tty);
1da177e4
LT
5065
5066 if (status == 0)
5067 portp->stats.rxtotal++;
5068 }
5069}
5070
5071/*****************************************************************************/
5072
5073/*
5074 * Process all characters in the RX FIFO of the UART. Check all char
5075 * status bytes as well, and process as required. We need to check
5076 * all bytes in the FIFO, in case some more enter the FIFO while we
5077 * are here. To get the exact character error type we need to switch
5078 * into CHAR error mode (that is why we need to make sure we empty
5079 * the FIFO).
5080 */
5081
5082static void stl_sc26198rxbadchars(stlport_t *portp)
5083{
5084 unsigned char status, mr1;
5085 char ch;
5086
5087/*
5088 * To get the precise error type for each character we must switch
5089 * back into CHAR error mode.
5090 */
5091 mr1 = stl_sc26198getreg(portp, MR1);
5092 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5093
5094 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5095 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5096 ch = stl_sc26198getreg(portp, RXFIFO);
5097 stl_sc26198rxbadch(portp, status, ch);
5098 }
5099
5100/*
5101 * To get correct interrupt class we must switch back into BLOCK
5102 * error mode.
5103 */
5104 stl_sc26198setreg(portp, MR1, mr1);
5105}
5106
5107/*****************************************************************************/
5108
5109/*
5110 * Other interrupt handler. This includes modem signals, flow
5111 * control actions, etc. Most stuff is left to off-level interrupt
5112 * processing time.
5113 */
5114
5115static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5116{
5117 unsigned char cir, ipr, xisr;
5118
5119#ifdef DEBUG
5120 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5121#endif
5122
5123 cir = stl_sc26198getglobreg(portp, CIR);
5124
5125 switch (cir & CIR_SUBTYPEMASK) {
5126 case CIR_SUBCOS:
5127 ipr = stl_sc26198getreg(portp, IPR);
5128 if (ipr & IPR_DCDCHANGE) {
5129 set_bit(ASYI_DCDCHANGE, &portp->istate);
5130 schedule_work(&portp->tqueue);
5131 portp->stats.modem++;
5132 }
5133 break;
5134 case CIR_SUBXONXOFF:
5135 xisr = stl_sc26198getreg(portp, XISR);
5136 if (xisr & XISR_RXXONGOT) {
5137 set_bit(ASYI_TXFLOWED, &portp->istate);
5138 portp->stats.txxoff++;
5139 }
5140 if (xisr & XISR_RXXOFFGOT) {
5141 clear_bit(ASYI_TXFLOWED, &portp->istate);
5142 portp->stats.txxon++;
5143 }
5144 break;
5145 case CIR_SUBBREAK:
5146 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5147 stl_sc26198rxbadchars(portp);
5148 break;
5149 default:
5150 break;
5151 }
5152}
5153
5154/*****************************************************************************/
This page took 0.372619 seconds and 5 git commands to generate.