1 /*****************************************************************************/
4 * istallion.c -- stallion intelligent multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/module.h>
30 #include <linux/slab.h>
31 #include <linux/interrupt.h>
32 #include <linux/tty.h>
33 #include <linux/tty_flip.h>
34 #include <linux/serial.h>
35 #include <linux/cdk.h>
36 #include <linux/comstats.h>
37 #include <linux/istallion.h>
38 #include <linux/ioport.h>
39 #include <linux/delay.h>
40 #include <linux/init.h>
41 #include <linux/device.h>
42 #include <linux/wait.h>
43 #include <linux/eisa.h>
46 #include <asm/uaccess.h>
48 #include <linux/pci.h>
50 /*****************************************************************************/
53 * Define different board types. Not all of the following board types
54 * are supported by this driver. But I will use the standard "assigned"
55 * board numbers. Currently supported boards are abbreviated as:
56 * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
60 #define BRD_STALLION 1
62 #define BRD_ONBOARD2 3
65 #define BRD_BRUMBY16 6
66 #define BRD_ONBOARDE 7
67 #define BRD_ONBOARD32 9
68 #define BRD_ONBOARD2_32 10
69 #define BRD_ONBOARDRS 11
77 #define BRD_ECH64PCI 27
78 #define BRD_EASYIOPCI 28
81 #define BRD_BRUMBY BRD_BRUMBY4
84 * Define a configuration structure to hold the board configuration.
85 * Need to set this up in the code (for now) with the boards that are
86 * to be configured into the system. This is what needs to be modified
87 * when adding/removing/modifying boards. Each line entry in the
88 * stli_brdconf[] array is a board. Each line contains io/irq/memory
89 * ranges for that board (as well as what type of board it is).
91 * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
92 * This line will configure an EasyConnection 8/64 at io address 2a0,
93 * and shared memory address of cc000. Multiple EasyConnection 8/64
94 * boards can share the same shared memory address space. No interrupt
95 * is required for this board type.
97 * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
98 * This line will configure an EasyConnection 8/64 EISA in slot 5 and
99 * shared memory address of 0x80000000 (2 GByte). Multiple
100 * EasyConnection 8/64 EISA boards can share the same shared memory
101 * address space. No interrupt is required for this board type.
103 * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
104 * This line will configure an ONboard (ISA type) at io address 240,
105 * and shared memory address of d0000. Multiple ONboards can share
106 * the same shared memory address space. No interrupt required.
108 * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
109 * This line will configure a Brumby board (any number of ports!) at
110 * io address 360 and shared memory address of c8000. All Brumby boards
111 * configured into a system must have their own separate io and memory
112 * addresses. No interrupt is required.
114 * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
115 * This line will configure an original Stallion board at io address 330
116 * and shared memory address d0000 (this would only be valid for a "V4.0"
117 * or Rev.O Stallion board). All Stallion boards configured into the
118 * system must have their own separate io and memory addresses. No
119 * interrupt is required.
126 unsigned long memaddr
;
131 static stlconf_t stli_brdconf
[] = {
132 /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
135 static int stli_nrbrds
= ARRAY_SIZE(stli_brdconf
);
137 /* stli_lock must NOT be taken holding brd_lock */
138 static spinlock_t stli_lock
; /* TTY logic lock */
139 static spinlock_t brd_lock
; /* Board logic lock */
142 * There is some experimental EISA board detection code in this driver.
143 * By default it is disabled, but for those that want to try it out,
144 * then set the define below to be 1.
146 #define STLI_EISAPROBE 0
148 /*****************************************************************************/
151 * Define some important driver characteristics. Device major numbers
152 * allocated as per Linux Device Registry.
154 #ifndef STL_SIOMEMMAJOR
155 #define STL_SIOMEMMAJOR 28
157 #ifndef STL_SERIALMAJOR
158 #define STL_SERIALMAJOR 24
160 #ifndef STL_CALLOUTMAJOR
161 #define STL_CALLOUTMAJOR 25
164 /*****************************************************************************/
167 * Define our local driver identity first. Set up stuff to deal with
168 * all the local structures required by a serial tty driver.
170 static char *stli_drvtitle
= "Stallion Intelligent Multiport Serial Driver";
171 static char *stli_drvname
= "istallion";
172 static char *stli_drvversion
= "5.6.0";
173 static char *stli_serialname
= "ttyE";
175 static struct tty_driver
*stli_serial
;
178 #define STLI_TXBUFSIZE 4096
181 * Use a fast local buffer for cooked characters. Typically a whole
182 * bunch of cooked characters come in for a port, 1 at a time. So we
183 * save those up into a local buffer, then write out the whole lot
184 * with a large memcpy. Just use 1 buffer for all ports, since its
185 * use it is only need for short periods of time by each port.
187 static char *stli_txcookbuf
;
188 static int stli_txcooksize
;
189 static int stli_txcookrealsize
;
190 static struct tty_struct
*stli_txcooktty
;
193 * Define a local default termios struct. All ports will be created
194 * with this termios initially. Basically all it defines is a raw port
195 * at 9600 baud, 8 data bits, no parity, 1 stop bit.
197 static struct termios stli_deftermios
= {
198 .c_cflag
= (B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
),
203 * Define global stats structures. Not used often, and can be
204 * re-used for each stats call.
206 static comstats_t stli_comstats
;
207 static combrd_t stli_brdstats
;
208 static asystats_t stli_cdkstats
;
209 static stlibrd_t stli_dummybrd
;
210 static stliport_t stli_dummyport
;
212 /*****************************************************************************/
214 static stlibrd_t
*stli_brds
[STL_MAXBRDS
];
216 static int stli_shared
;
219 * Per board state flags. Used with the state field of the board struct.
220 * Not really much here... All we need to do is keep track of whether
221 * the board has been detected, and whether it is actually running a slave
224 #define BST_FOUND 0x1
225 #define BST_STARTED 0x2
228 * Define the set of port state flags. These are marked for internal
229 * state purposes only, usually to do with the state of communications
230 * with the slave. Most of them need to be updated atomically, so always
231 * use the bit setting operations (unless protected by cli/sti).
233 #define ST_INITIALIZING 1
239 #define ST_DOFLUSHRX 7
240 #define ST_DOFLUSHTX 8
243 #define ST_GETSIGS 11
246 * Define an array of board names as printable strings. Handy for
247 * referencing boards when printing trace and stuff.
249 static char *stli_brdnames
[] = {
282 /*****************************************************************************/
285 * Define some string labels for arguments passed from the module
286 * load line. These allow for easy board definitions, and easy
287 * modification of the io, memory and irq resoucres.
290 static char *board0
[8];
291 static char *board1
[8];
292 static char *board2
[8];
293 static char *board3
[8];
295 static char **stli_brdsp
[] = {
303 * Define a set of common board names, and types. This is used to
304 * parse any module arguments.
307 typedef struct stlibrdtype
{
312 static stlibrdtype_t stli_brdstr
[] = {
313 { "stallion", BRD_STALLION
},
314 { "1", BRD_STALLION
},
315 { "brumby", BRD_BRUMBY
},
316 { "brumby4", BRD_BRUMBY
},
317 { "brumby/4", BRD_BRUMBY
},
318 { "brumby-4", BRD_BRUMBY
},
319 { "brumby8", BRD_BRUMBY
},
320 { "brumby/8", BRD_BRUMBY
},
321 { "brumby-8", BRD_BRUMBY
},
322 { "brumby16", BRD_BRUMBY
},
323 { "brumby/16", BRD_BRUMBY
},
324 { "brumby-16", BRD_BRUMBY
},
326 { "onboard2", BRD_ONBOARD2
},
327 { "onboard-2", BRD_ONBOARD2
},
328 { "onboard/2", BRD_ONBOARD2
},
329 { "onboard-mc", BRD_ONBOARD2
},
330 { "onboard/mc", BRD_ONBOARD2
},
331 { "onboard-mca", BRD_ONBOARD2
},
332 { "onboard/mca", BRD_ONBOARD2
},
333 { "3", BRD_ONBOARD2
},
334 { "onboard", BRD_ONBOARD
},
335 { "onboardat", BRD_ONBOARD
},
336 { "4", BRD_ONBOARD
},
337 { "onboarde", BRD_ONBOARDE
},
338 { "onboard-e", BRD_ONBOARDE
},
339 { "onboard/e", BRD_ONBOARDE
},
340 { "onboard-ei", BRD_ONBOARDE
},
341 { "onboard/ei", BRD_ONBOARDE
},
342 { "7", BRD_ONBOARDE
},
344 { "ecpat", BRD_ECP
},
345 { "ec8/64", BRD_ECP
},
346 { "ec8/64-at", BRD_ECP
},
347 { "ec8/64-isa", BRD_ECP
},
349 { "ecpe", BRD_ECPE
},
350 { "ecpei", BRD_ECPE
},
351 { "ec8/64-e", BRD_ECPE
},
352 { "ec8/64-ei", BRD_ECPE
},
354 { "ecpmc", BRD_ECPMC
},
355 { "ec8/64-mc", BRD_ECPMC
},
356 { "ec8/64-mca", BRD_ECPMC
},
358 { "ecppci", BRD_ECPPCI
},
359 { "ec/ra", BRD_ECPPCI
},
360 { "ec/ra-pc", BRD_ECPPCI
},
361 { "ec/ra-pci", BRD_ECPPCI
},
362 { "29", BRD_ECPPCI
},
366 * Define the module agruments.
368 MODULE_AUTHOR("Greg Ungerer");
369 MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
370 MODULE_LICENSE("GPL");
373 module_param_array(board0
, charp
, NULL
, 0);
374 MODULE_PARM_DESC(board0
, "Board 0 config -> name[,ioaddr[,memaddr]");
375 module_param_array(board1
, charp
, NULL
, 0);
376 MODULE_PARM_DESC(board1
, "Board 1 config -> name[,ioaddr[,memaddr]");
377 module_param_array(board2
, charp
, NULL
, 0);
378 MODULE_PARM_DESC(board2
, "Board 2 config -> name[,ioaddr[,memaddr]");
379 module_param_array(board3
, charp
, NULL
, 0);
380 MODULE_PARM_DESC(board3
, "Board 3 config -> name[,ioaddr[,memaddr]");
383 * Set up a default memory address table for EISA board probing.
384 * The default addresses are all bellow 1Mbyte, which has to be the
385 * case anyway. They should be safe, since we only read values from
386 * them, and interrupts are disabled while we do it. If the higher
387 * memory support is compiled in then we also try probing around
388 * the 1Gb, 2Gb and 3Gb areas as well...
390 static unsigned long stli_eisamemprobeaddrs
[] = {
391 0xc0000, 0xd0000, 0xe0000, 0xf0000,
392 0x80000000, 0x80010000, 0x80020000, 0x80030000,
393 0x40000000, 0x40010000, 0x40020000, 0x40030000,
394 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
395 0xff000000, 0xff010000, 0xff020000, 0xff030000,
398 static int stli_eisamempsize
= ARRAY_SIZE(stli_eisamemprobeaddrs
);
401 * Define the Stallion PCI vendor and device IDs.
404 #ifndef PCI_VENDOR_ID_STALLION
405 #define PCI_VENDOR_ID_STALLION 0x124d
407 #ifndef PCI_DEVICE_ID_ECRA
408 #define PCI_DEVICE_ID_ECRA 0x0004
411 static struct pci_device_id istallion_pci_tbl
[] = {
412 { PCI_DEVICE(PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECRA
), },
415 MODULE_DEVICE_TABLE(pci
, istallion_pci_tbl
);
417 #endif /* CONFIG_PCI */
419 /*****************************************************************************/
422 * Hardware configuration info for ECP boards. These defines apply
423 * to the directly accessible io ports of the ECP. There is a set of
424 * defines for each ECP board type, ISA, EISA, MCA and PCI.
428 #define ECP_MEMSIZE (128 * 1024)
429 #define ECP_PCIMEMSIZE (256 * 1024)
431 #define ECP_ATPAGESIZE (4 * 1024)
432 #define ECP_MCPAGESIZE (4 * 1024)
433 #define ECP_EIPAGESIZE (64 * 1024)
434 #define ECP_PCIPAGESIZE (64 * 1024)
436 #define STL_EISAID 0x8c4e
439 * Important defines for the ISA class of ECP board.
442 #define ECP_ATCONFR 1
443 #define ECP_ATMEMAR 2
444 #define ECP_ATMEMPR 3
445 #define ECP_ATSTOP 0x1
446 #define ECP_ATINTENAB 0x10
447 #define ECP_ATENABLE 0x20
448 #define ECP_ATDISABLE 0x00
449 #define ECP_ATADDRMASK 0x3f000
450 #define ECP_ATADDRSHFT 12
453 * Important defines for the EISA class of ECP board.
456 #define ECP_EIMEMARL 1
457 #define ECP_EICONFR 2
458 #define ECP_EIMEMARH 3
459 #define ECP_EIENABLE 0x1
460 #define ECP_EIDISABLE 0x0
461 #define ECP_EISTOP 0x4
462 #define ECP_EIEDGE 0x00
463 #define ECP_EILEVEL 0x80
464 #define ECP_EIADDRMASKL 0x00ff0000
465 #define ECP_EIADDRSHFTL 16
466 #define ECP_EIADDRMASKH 0xff000000
467 #define ECP_EIADDRSHFTH 24
468 #define ECP_EIBRDENAB 0xc84
470 #define ECP_EISAID 0x4
473 * Important defines for the Micro-channel class of ECP board.
474 * (It has a lot in common with the ISA boards.)
477 #define ECP_MCCONFR 1
478 #define ECP_MCSTOP 0x20
479 #define ECP_MCENABLE 0x80
480 #define ECP_MCDISABLE 0x00
483 * Important defines for the PCI class of ECP board.
484 * (It has a lot in common with the other ECP boards.)
486 #define ECP_PCIIREG 0
487 #define ECP_PCICONFR 1
488 #define ECP_PCISTOP 0x01
491 * Hardware configuration info for ONboard and Brumby boards. These
492 * defines apply to the directly accessible io ports of these boards.
494 #define ONB_IOSIZE 16
495 #define ONB_MEMSIZE (64 * 1024)
496 #define ONB_ATPAGESIZE (64 * 1024)
497 #define ONB_MCPAGESIZE (64 * 1024)
498 #define ONB_EIMEMSIZE (128 * 1024)
499 #define ONB_EIPAGESIZE (64 * 1024)
502 * Important defines for the ISA class of ONboard board.
505 #define ONB_ATMEMAR 1
506 #define ONB_ATCONFR 2
507 #define ONB_ATSTOP 0x4
508 #define ONB_ATENABLE 0x01
509 #define ONB_ATDISABLE 0x00
510 #define ONB_ATADDRMASK 0xff0000
511 #define ONB_ATADDRSHFT 16
513 #define ONB_MEMENABLO 0
514 #define ONB_MEMENABHI 0x02
517 * Important defines for the EISA class of ONboard board.
520 #define ONB_EIMEMARL 1
521 #define ONB_EICONFR 2
522 #define ONB_EIMEMARH 3
523 #define ONB_EIENABLE 0x1
524 #define ONB_EIDISABLE 0x0
525 #define ONB_EISTOP 0x4
526 #define ONB_EIEDGE 0x00
527 #define ONB_EILEVEL 0x80
528 #define ONB_EIADDRMASKL 0x00ff0000
529 #define ONB_EIADDRSHFTL 16
530 #define ONB_EIADDRMASKH 0xff000000
531 #define ONB_EIADDRSHFTH 24
532 #define ONB_EIBRDENAB 0xc84
534 #define ONB_EISAID 0x1
537 * Important defines for the Brumby boards. They are pretty simple,
538 * there is not much that is programmably configurable.
540 #define BBY_IOSIZE 16
541 #define BBY_MEMSIZE (64 * 1024)
542 #define BBY_PAGESIZE (16 * 1024)
545 #define BBY_ATCONFR 1
546 #define BBY_ATSTOP 0x4
549 * Important defines for the Stallion boards. They are pretty simple,
550 * there is not much that is programmably configurable.
552 #define STAL_IOSIZE 16
553 #define STAL_MEMSIZE (64 * 1024)
554 #define STAL_PAGESIZE (64 * 1024)
557 * Define the set of status register values for EasyConnection panels.
558 * The signature will return with the status value for each panel. From
559 * this we can determine what is attached to the board - before we have
560 * actually down loaded any code to it.
562 #define ECH_PNLSTATUS 2
563 #define ECH_PNL16PORT 0x20
564 #define ECH_PNLIDMASK 0x07
565 #define ECH_PNLXPID 0x40
566 #define ECH_PNLINTRPEND 0x80
569 * Define some macros to do things to the board. Even those these boards
570 * are somewhat related there is often significantly different ways of
571 * doing some operation on it (like enable, paging, reset, etc). So each
572 * board class has a set of functions which do the commonly required
573 * operations. The macros below basically just call these functions,
574 * generally checking for a NULL function - which means that the board
575 * needs nothing done to it to achieve this operation!
577 #define EBRDINIT(brdp) \
578 if (brdp->init != NULL) \
581 #define EBRDENABLE(brdp) \
582 if (brdp->enable != NULL) \
583 (* brdp->enable)(brdp);
585 #define EBRDDISABLE(brdp) \
586 if (brdp->disable != NULL) \
587 (* brdp->disable)(brdp);
589 #define EBRDINTR(brdp) \
590 if (brdp->intr != NULL) \
591 (* brdp->intr)(brdp);
593 #define EBRDRESET(brdp) \
594 if (brdp->reset != NULL) \
595 (* brdp->reset)(brdp);
597 #define EBRDGETMEMPTR(brdp,offset) \
598 (* brdp->getmemptr)(brdp, offset, __LINE__)
601 * Define the maximal baud rate, and the default baud base for ports.
603 #define STL_MAXBAUD 460800
604 #define STL_BAUDBASE 115200
605 #define STL_CLOSEDELAY (5 * HZ / 10)
607 /*****************************************************************************/
610 * Define macros to extract a brd or port number from a minor number.
612 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
613 #define MINOR2PORT(min) ((min) & 0x3f)
615 /*****************************************************************************/
618 * Define some handy local macros...
621 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
624 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
626 /*****************************************************************************/
629 * Prototype all functions in this driver!
632 static int stli_parsebrd(stlconf_t
*confp
, char **argp
);
633 static int stli_init(void);
634 static int stli_open(struct tty_struct
*tty
, struct file
*filp
);
635 static void stli_close(struct tty_struct
*tty
, struct file
*filp
);
636 static int stli_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
);
637 static void stli_putchar(struct tty_struct
*tty
, unsigned char ch
);
638 static void stli_flushchars(struct tty_struct
*tty
);
639 static int stli_writeroom(struct tty_struct
*tty
);
640 static int stli_charsinbuffer(struct tty_struct
*tty
);
641 static int stli_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
);
642 static void stli_settermios(struct tty_struct
*tty
, struct termios
*old
);
643 static void stli_throttle(struct tty_struct
*tty
);
644 static void stli_unthrottle(struct tty_struct
*tty
);
645 static void stli_stop(struct tty_struct
*tty
);
646 static void stli_start(struct tty_struct
*tty
);
647 static void stli_flushbuffer(struct tty_struct
*tty
);
648 static void stli_breakctl(struct tty_struct
*tty
, int state
);
649 static void stli_waituntilsent(struct tty_struct
*tty
, int timeout
);
650 static void stli_sendxchar(struct tty_struct
*tty
, char ch
);
651 static void stli_hangup(struct tty_struct
*tty
);
652 static int stli_portinfo(stlibrd_t
*brdp
, stliport_t
*portp
, int portnr
, char *pos
);
654 static int stli_brdinit(stlibrd_t
*brdp
);
655 static int stli_startbrd(stlibrd_t
*brdp
);
656 static ssize_t
stli_memread(struct file
*fp
, char __user
*buf
, size_t count
, loff_t
*offp
);
657 static ssize_t
stli_memwrite(struct file
*fp
, const char __user
*buf
, size_t count
, loff_t
*offp
);
658 static int stli_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
);
659 static void stli_brdpoll(stlibrd_t
*brdp
, cdkhdr_t __iomem
*hdrp
);
660 static void stli_poll(unsigned long arg
);
661 static int stli_hostcmd(stlibrd_t
*brdp
, stliport_t
*portp
);
662 static int stli_initopen(stlibrd_t
*brdp
, stliport_t
*portp
);
663 static int stli_rawopen(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long arg
, int wait
);
664 static int stli_rawclose(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long arg
, int wait
);
665 static int stli_waitcarrier(stlibrd_t
*brdp
, stliport_t
*portp
, struct file
*filp
);
666 static void stli_dohangup(void *arg
);
667 static int stli_setport(stliport_t
*portp
);
668 static int stli_cmdwait(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long cmd
, void *arg
, int size
, int copyback
);
669 static void stli_sendcmd(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long cmd
, void *arg
, int size
, int copyback
);
670 static void __stli_sendcmd(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long cmd
, void *arg
, int size
, int copyback
);
671 static void stli_dodelaycmd(stliport_t
*portp
, cdkctrl_t __iomem
*cp
);
672 static void stli_mkasyport(stliport_t
*portp
, asyport_t
*pp
, struct termios
*tiosp
);
673 static void stli_mkasysigs(asysigs_t
*sp
, int dtr
, int rts
);
674 static long stli_mktiocm(unsigned long sigvalue
);
675 static void stli_read(stlibrd_t
*brdp
, stliport_t
*portp
);
676 static int stli_getserial(stliport_t
*portp
, struct serial_struct __user
*sp
);
677 static int stli_setserial(stliport_t
*portp
, struct serial_struct __user
*sp
);
678 static int stli_getbrdstats(combrd_t __user
*bp
);
679 static int stli_getportstats(stliport_t
*portp
, comstats_t __user
*cp
);
680 static int stli_portcmdstats(stliport_t
*portp
);
681 static int stli_clrportstats(stliport_t
*portp
, comstats_t __user
*cp
);
682 static int stli_getportstruct(stliport_t __user
*arg
);
683 static int stli_getbrdstruct(stlibrd_t __user
*arg
);
684 static stlibrd_t
*stli_allocbrd(void);
686 static void stli_ecpinit(stlibrd_t
*brdp
);
687 static void stli_ecpenable(stlibrd_t
*brdp
);
688 static void stli_ecpdisable(stlibrd_t
*brdp
);
689 static void __iomem
*stli_ecpgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
690 static void stli_ecpreset(stlibrd_t
*brdp
);
691 static void stli_ecpintr(stlibrd_t
*brdp
);
692 static void stli_ecpeiinit(stlibrd_t
*brdp
);
693 static void stli_ecpeienable(stlibrd_t
*brdp
);
694 static void stli_ecpeidisable(stlibrd_t
*brdp
);
695 static void __iomem
*stli_ecpeigetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
696 static void stli_ecpeireset(stlibrd_t
*brdp
);
697 static void stli_ecpmcenable(stlibrd_t
*brdp
);
698 static void stli_ecpmcdisable(stlibrd_t
*brdp
);
699 static void __iomem
*stli_ecpmcgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
700 static void stli_ecpmcreset(stlibrd_t
*brdp
);
701 static void stli_ecppciinit(stlibrd_t
*brdp
);
702 static void __iomem
*stli_ecppcigetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
703 static void stli_ecppcireset(stlibrd_t
*brdp
);
705 static void stli_onbinit(stlibrd_t
*brdp
);
706 static void stli_onbenable(stlibrd_t
*brdp
);
707 static void stli_onbdisable(stlibrd_t
*brdp
);
708 static void __iomem
*stli_onbgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
709 static void stli_onbreset(stlibrd_t
*brdp
);
710 static void stli_onbeinit(stlibrd_t
*brdp
);
711 static void stli_onbeenable(stlibrd_t
*brdp
);
712 static void stli_onbedisable(stlibrd_t
*brdp
);
713 static void __iomem
*stli_onbegetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
714 static void stli_onbereset(stlibrd_t
*brdp
);
715 static void stli_bbyinit(stlibrd_t
*brdp
);
716 static void __iomem
*stli_bbygetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
717 static void stli_bbyreset(stlibrd_t
*brdp
);
718 static void stli_stalinit(stlibrd_t
*brdp
);
719 static void __iomem
*stli_stalgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
);
720 static void stli_stalreset(stlibrd_t
*brdp
);
722 static stliport_t
*stli_getport(int brdnr
, int panelnr
, int portnr
);
724 static int stli_initecp(stlibrd_t
*brdp
);
725 static int stli_initonb(stlibrd_t
*brdp
);
726 static int stli_eisamemprobe(stlibrd_t
*brdp
);
727 static int stli_initports(stlibrd_t
*brdp
);
730 static int stli_initpcibrd(int brdtype
, struct pci_dev
*devp
);
733 /*****************************************************************************/
736 * Define the driver info for a user level shared memory device. This
737 * device will work sort of like the /dev/kmem device - except that it
738 * will give access to the shared memory on the Stallion intelligent
739 * board. This is also a very useful debugging tool.
741 static const struct file_operations stli_fsiomem
= {
742 .owner
= THIS_MODULE
,
743 .read
= stli_memread
,
744 .write
= stli_memwrite
,
745 .ioctl
= stli_memioctl
,
748 /*****************************************************************************/
751 * Define a timer_list entry for our poll routine. The slave board
752 * is polled every so often to see if anything needs doing. This is
753 * much cheaper on host cpu than using interrupts. It turns out to
754 * not increase character latency by much either...
756 static DEFINE_TIMER(stli_timerlist
, stli_poll
, 0, 0);
758 static int stli_timeron
;
761 * Define the calculation for the timeout routine.
763 #define STLI_TIMEOUT (jiffies + 1)
765 /*****************************************************************************/
767 static struct class *istallion_class
;
770 * Loadable module initialization stuff.
773 static int __init
istallion_module_init(void)
779 /*****************************************************************************/
781 static void __exit
istallion_module_exit(void)
787 printk(KERN_INFO
"Unloading %s: version %s\n", stli_drvtitle
,
791 * Free up all allocated resources used by the ports. This includes
792 * memory and interrupts.
796 del_timer_sync(&stli_timerlist
);
799 i
= tty_unregister_driver(stli_serial
);
801 printk("STALLION: failed to un-register tty driver, "
805 put_tty_driver(stli_serial
);
806 for (i
= 0; i
< 4; i
++)
807 class_device_destroy(istallion_class
, MKDEV(STL_SIOMEMMAJOR
, i
));
808 class_destroy(istallion_class
);
809 if ((i
= unregister_chrdev(STL_SIOMEMMAJOR
, "staliomem")))
810 printk("STALLION: failed to un-register serial memory device, "
813 kfree(stli_txcookbuf
);
815 for (i
= 0; (i
< stli_nrbrds
); i
++) {
816 if ((brdp
= stli_brds
[i
]) == NULL
)
818 for (j
= 0; (j
< STL_MAXPORTS
); j
++) {
819 portp
= brdp
->ports
[j
];
821 if (portp
->tty
!= NULL
)
822 tty_hangup(portp
->tty
);
827 iounmap(brdp
->membase
);
828 if (brdp
->iosize
> 0)
829 release_region(brdp
->iobase
, brdp
->iosize
);
835 module_init(istallion_module_init
);
836 module_exit(istallion_module_exit
);
838 /*****************************************************************************/
841 * Check for any arguments passed in on the module load command line.
844 static void stli_argbrds(void)
850 for (i
= stli_nrbrds
; i
< ARRAY_SIZE(stli_brdsp
); i
++) {
851 memset(&conf
, 0, sizeof(conf
));
852 if (stli_parsebrd(&conf
, stli_brdsp
[i
]) == 0)
854 if ((brdp
= stli_allocbrd()) == NULL
)
858 brdp
->brdtype
= conf
.brdtype
;
859 brdp
->iobase
= conf
.ioaddr1
;
860 brdp
->memaddr
= conf
.memaddr
;
865 /*****************************************************************************/
868 * Convert an ascii string number into an unsigned long.
871 static unsigned long stli_atol(char *str
)
879 if ((*sp
== '0') && (*(sp
+1) == 'x')) {
882 } else if (*sp
== '0') {
889 for (; (*sp
!= 0); sp
++) {
890 c
= (*sp
> '9') ? (TOLOWER(*sp
) - 'a' + 10) : (*sp
- '0');
891 if ((c
< 0) || (c
>= base
)) {
892 printk("STALLION: invalid argument %s\n", str
);
896 val
= (val
* base
) + c
;
901 /*****************************************************************************/
904 * Parse the supplied argument string, into the board conf struct.
907 static int stli_parsebrd(stlconf_t
*confp
, char **argp
)
912 if (argp
[0] == NULL
|| *argp
[0] == 0)
915 for (sp
= argp
[0], i
= 0; ((*sp
!= 0) && (i
< 25)); sp
++, i
++)
918 for (i
= 0; i
< ARRAY_SIZE(stli_brdstr
); i
++) {
919 if (strcmp(stli_brdstr
[i
].name
, argp
[0]) == 0)
922 if (i
== ARRAY_SIZE(stli_brdstr
)) {
923 printk("STALLION: unknown board name, %s?\n", argp
[0]);
927 confp
->brdtype
= stli_brdstr
[i
].type
;
928 if (argp
[1] != NULL
&& *argp
[1] != 0)
929 confp
->ioaddr1
= stli_atol(argp
[1]);
930 if (argp
[2] != NULL
&& *argp
[2] != 0)
931 confp
->memaddr
= stli_atol(argp
[2]);
935 /*****************************************************************************/
937 static int stli_open(struct tty_struct
*tty
, struct file
*filp
)
941 unsigned int minordev
;
942 int brdnr
, portnr
, rc
;
944 minordev
= tty
->index
;
945 brdnr
= MINOR2BRD(minordev
);
946 if (brdnr
>= stli_nrbrds
)
948 brdp
= stli_brds
[brdnr
];
951 if ((brdp
->state
& BST_STARTED
) == 0)
953 portnr
= MINOR2PORT(minordev
);
954 if ((portnr
< 0) || (portnr
> brdp
->nrports
))
957 portp
= brdp
->ports
[portnr
];
960 if (portp
->devnr
< 1)
965 * Check if this port is in the middle of closing. If so then wait
966 * until it is closed then return error status based on flag settings.
967 * The sleep here does not need interrupt protection since the wakeup
968 * for it is done with the same context.
970 if (portp
->flags
& ASYNC_CLOSING
) {
971 interruptible_sleep_on(&portp
->close_wait
);
972 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
978 * On the first open of the device setup the port hardware, and
979 * initialize the per port data structure. Since initializing the port
980 * requires several commands to the board we will need to wait for any
981 * other open that is already initializing the port.
984 tty
->driver_data
= portp
;
987 wait_event_interruptible(portp
->raw_wait
,
988 !test_bit(ST_INITIALIZING
, &portp
->state
));
989 if (signal_pending(current
))
992 if ((portp
->flags
& ASYNC_INITIALIZED
) == 0) {
993 set_bit(ST_INITIALIZING
, &portp
->state
);
994 if ((rc
= stli_initopen(brdp
, portp
)) >= 0) {
995 portp
->flags
|= ASYNC_INITIALIZED
;
996 clear_bit(TTY_IO_ERROR
, &tty
->flags
);
998 clear_bit(ST_INITIALIZING
, &portp
->state
);
999 wake_up_interruptible(&portp
->raw_wait
);
1005 * Check if this port is in the middle of closing. If so then wait
1006 * until it is closed then return error status, based on flag settings.
1007 * The sleep here does not need interrupt protection since the wakeup
1008 * for it is done with the same context.
1010 if (portp
->flags
& ASYNC_CLOSING
) {
1011 interruptible_sleep_on(&portp
->close_wait
);
1012 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1014 return -ERESTARTSYS
;
1018 * Based on type of open being done check if it can overlap with any
1019 * previous opens still in effect. If we are a normal serial device
1020 * then also we might have to wait for carrier.
1022 if (!(filp
->f_flags
& O_NONBLOCK
)) {
1023 if ((rc
= stli_waitcarrier(brdp
, portp
, filp
)) != 0)
1026 portp
->flags
|= ASYNC_NORMAL_ACTIVE
;
1030 /*****************************************************************************/
1032 static void stli_close(struct tty_struct
*tty
, struct file
*filp
)
1036 unsigned long flags
;
1038 portp
= tty
->driver_data
;
1042 spin_lock_irqsave(&stli_lock
, flags
);
1043 if (tty_hung_up_p(filp
)) {
1044 spin_unlock_irqrestore(&stli_lock
, flags
);
1047 if ((tty
->count
== 1) && (portp
->refcount
!= 1))
1048 portp
->refcount
= 1;
1049 if (portp
->refcount
-- > 1) {
1050 spin_unlock_irqrestore(&stli_lock
, flags
);
1054 portp
->flags
|= ASYNC_CLOSING
;
1057 * May want to wait for data to drain before closing. The BUSY flag
1058 * keeps track of whether we are still transmitting or not. It is
1059 * updated by messages from the slave - indicating when all chars
1060 * really have drained.
1062 if (tty
== stli_txcooktty
)
1063 stli_flushchars(tty
);
1065 spin_unlock_irqrestore(&stli_lock
, flags
);
1067 if (portp
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1068 tty_wait_until_sent(tty
, portp
->closing_wait
);
1070 portp
->flags
&= ~ASYNC_INITIALIZED
;
1071 brdp
= stli_brds
[portp
->brdnr
];
1072 stli_rawclose(brdp
, portp
, 0, 0);
1073 if (tty
->termios
->c_cflag
& HUPCL
) {
1074 stli_mkasysigs(&portp
->asig
, 0, 0);
1075 if (test_bit(ST_CMDING
, &portp
->state
))
1076 set_bit(ST_DOSIGS
, &portp
->state
);
1078 stli_sendcmd(brdp
, portp
, A_SETSIGNALS
, &portp
->asig
,
1079 sizeof(asysigs_t
), 0);
1081 clear_bit(ST_TXBUSY
, &portp
->state
);
1082 clear_bit(ST_RXSTOP
, &portp
->state
);
1083 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1084 if (tty
->ldisc
.flush_buffer
)
1085 (tty
->ldisc
.flush_buffer
)(tty
);
1086 set_bit(ST_DOFLUSHRX
, &portp
->state
);
1087 stli_flushbuffer(tty
);
1092 if (portp
->openwaitcnt
) {
1093 if (portp
->close_delay
)
1094 msleep_interruptible(jiffies_to_msecs(portp
->close_delay
));
1095 wake_up_interruptible(&portp
->open_wait
);
1098 portp
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1099 wake_up_interruptible(&portp
->close_wait
);
1102 /*****************************************************************************/
1105 * Carry out first open operations on a port. This involves a number of
1106 * commands to be sent to the slave. We need to open the port, set the
1107 * notification events, set the initial port settings, get and set the
1108 * initial signal values. We sleep and wait in between each one. But
1109 * this still all happens pretty quickly.
1112 static int stli_initopen(stlibrd_t
*brdp
, stliport_t
*portp
)
1114 struct tty_struct
*tty
;
1119 if ((rc
= stli_rawopen(brdp
, portp
, 0, 1)) < 0)
1122 memset(&nt
, 0, sizeof(asynotify_t
));
1123 nt
.data
= (DT_TXLOW
| DT_TXEMPTY
| DT_RXBUSY
| DT_RXBREAK
);
1125 if ((rc
= stli_cmdwait(brdp
, portp
, A_SETNOTIFY
, &nt
,
1126 sizeof(asynotify_t
), 0)) < 0)
1132 stli_mkasyport(portp
, &aport
, tty
->termios
);
1133 if ((rc
= stli_cmdwait(brdp
, portp
, A_SETPORT
, &aport
,
1134 sizeof(asyport_t
), 0)) < 0)
1137 set_bit(ST_GETSIGS
, &portp
->state
);
1138 if ((rc
= stli_cmdwait(brdp
, portp
, A_GETSIGNALS
, &portp
->asig
,
1139 sizeof(asysigs_t
), 1)) < 0)
1141 if (test_and_clear_bit(ST_GETSIGS
, &portp
->state
))
1142 portp
->sigs
= stli_mktiocm(portp
->asig
.sigvalue
);
1143 stli_mkasysigs(&portp
->asig
, 1, 1);
1144 if ((rc
= stli_cmdwait(brdp
, portp
, A_SETSIGNALS
, &portp
->asig
,
1145 sizeof(asysigs_t
), 0)) < 0)
1151 /*****************************************************************************/
1154 * Send an open message to the slave. This will sleep waiting for the
1155 * acknowledgement, so must have user context. We need to co-ordinate
1156 * with close events here, since we don't want open and close events
1160 static int stli_rawopen(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long arg
, int wait
)
1162 cdkhdr_t __iomem
*hdrp
;
1163 cdkctrl_t __iomem
*cp
;
1164 unsigned char __iomem
*bits
;
1165 unsigned long flags
;
1169 * Send a message to the slave to open this port.
1173 * Slave is already closing this port. This can happen if a hangup
1174 * occurs on this port. So we must wait until it is complete. The
1175 * order of opens and closes may not be preserved across shared
1176 * memory, so we must wait until it is complete.
1178 wait_event_interruptible(portp
->raw_wait
,
1179 !test_bit(ST_CLOSING
, &portp
->state
));
1180 if (signal_pending(current
)) {
1181 return -ERESTARTSYS
;
1185 * Everything is ready now, so write the open message into shared
1186 * memory. Once the message is in set the service bits to say that
1187 * this port wants service.
1189 spin_lock_irqsave(&brd_lock
, flags
);
1191 cp
= &((cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->ctrl
;
1192 writel(arg
, &cp
->openarg
);
1193 writeb(1, &cp
->open
);
1194 hdrp
= (cdkhdr_t __iomem
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
1195 bits
= ((unsigned char __iomem
*) hdrp
) + brdp
->slaveoffset
+
1197 writeb(readb(bits
) | portp
->portbit
, bits
);
1201 spin_unlock_irqrestore(&brd_lock
, flags
);
1206 * Slave is in action, so now we must wait for the open acknowledgment
1210 set_bit(ST_OPENING
, &portp
->state
);
1211 spin_unlock_irqrestore(&brd_lock
, flags
);
1213 wait_event_interruptible(portp
->raw_wait
,
1214 !test_bit(ST_OPENING
, &portp
->state
));
1215 if (signal_pending(current
))
1218 if ((rc
== 0) && (portp
->rc
!= 0))
1223 /*****************************************************************************/
1226 * Send a close message to the slave. Normally this will sleep waiting
1227 * for the acknowledgement, but if wait parameter is 0 it will not. If
1228 * wait is true then must have user context (to sleep).
1231 static int stli_rawclose(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long arg
, int wait
)
1233 cdkhdr_t __iomem
*hdrp
;
1234 cdkctrl_t __iomem
*cp
;
1235 unsigned char __iomem
*bits
;
1236 unsigned long flags
;
1240 * Slave is already closing this port. This can happen if a hangup
1241 * occurs on this port.
1244 wait_event_interruptible(portp
->raw_wait
,
1245 !test_bit(ST_CLOSING
, &portp
->state
));
1246 if (signal_pending(current
)) {
1247 return -ERESTARTSYS
;
1252 * Write the close command into shared memory.
1254 spin_lock_irqsave(&brd_lock
, flags
);
1256 cp
= &((cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->ctrl
;
1257 writel(arg
, &cp
->closearg
);
1258 writeb(1, &cp
->close
);
1259 hdrp
= (cdkhdr_t __iomem
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
1260 bits
= ((unsigned char __iomem
*) hdrp
) + brdp
->slaveoffset
+
1262 writeb(readb(bits
) |portp
->portbit
, bits
);
1265 set_bit(ST_CLOSING
, &portp
->state
);
1266 spin_unlock_irqrestore(&brd_lock
, flags
);
1272 * Slave is in action, so now we must wait for the open acknowledgment
1276 wait_event_interruptible(portp
->raw_wait
,
1277 !test_bit(ST_CLOSING
, &portp
->state
));
1278 if (signal_pending(current
))
1281 if ((rc
== 0) && (portp
->rc
!= 0))
1286 /*****************************************************************************/
1289 * Send a command to the slave and wait for the response. This must
1290 * have user context (it sleeps). This routine is generic in that it
1291 * can send any type of command. Its purpose is to wait for that command
1292 * to complete (as opposed to initiating the command then returning).
1295 static int stli_cmdwait(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long cmd
, void *arg
, int size
, int copyback
)
1297 wait_event_interruptible(portp
->raw_wait
,
1298 !test_bit(ST_CMDING
, &portp
->state
));
1299 if (signal_pending(current
))
1300 return -ERESTARTSYS
;
1302 stli_sendcmd(brdp
, portp
, cmd
, arg
, size
, copyback
);
1304 wait_event_interruptible(portp
->raw_wait
,
1305 !test_bit(ST_CMDING
, &portp
->state
));
1306 if (signal_pending(current
))
1307 return -ERESTARTSYS
;
1314 /*****************************************************************************/
1317 * Send the termios settings for this port to the slave. This sleeps
1318 * waiting for the command to complete - so must have user context.
1321 static int stli_setport(stliport_t
*portp
)
1328 if (portp
->tty
== NULL
)
1330 if (portp
->brdnr
< 0 && portp
->brdnr
>= stli_nrbrds
)
1332 brdp
= stli_brds
[portp
->brdnr
];
1336 stli_mkasyport(portp
, &aport
, portp
->tty
->termios
);
1337 return(stli_cmdwait(brdp
, portp
, A_SETPORT
, &aport
, sizeof(asyport_t
), 0));
1340 /*****************************************************************************/
1343 * Possibly need to wait for carrier (DCD signal) to come high. Say
1344 * maybe because if we are clocal then we don't need to wait...
1347 static int stli_waitcarrier(stlibrd_t
*brdp
, stliport_t
*portp
, struct file
*filp
)
1349 unsigned long flags
;
1355 if (portp
->tty
->termios
->c_cflag
& CLOCAL
)
1358 spin_lock_irqsave(&stli_lock
, flags
);
1359 portp
->openwaitcnt
++;
1360 if (! tty_hung_up_p(filp
))
1362 spin_unlock_irqrestore(&stli_lock
, flags
);
1365 stli_mkasysigs(&portp
->asig
, 1, 1);
1366 if ((rc
= stli_cmdwait(brdp
, portp
, A_SETSIGNALS
,
1367 &portp
->asig
, sizeof(asysigs_t
), 0)) < 0)
1369 if (tty_hung_up_p(filp
) ||
1370 ((portp
->flags
& ASYNC_INITIALIZED
) == 0)) {
1371 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1377 if (((portp
->flags
& ASYNC_CLOSING
) == 0) &&
1378 (doclocal
|| (portp
->sigs
& TIOCM_CD
))) {
1381 if (signal_pending(current
)) {
1385 interruptible_sleep_on(&portp
->open_wait
);
1388 spin_lock_irqsave(&stli_lock
, flags
);
1389 if (! tty_hung_up_p(filp
))
1391 portp
->openwaitcnt
--;
1392 spin_unlock_irqrestore(&stli_lock
, flags
);
1397 /*****************************************************************************/
1400 * Write routine. Take the data and put it in the shared memory ring
1401 * queue. If port is not already sending chars then need to mark the
1402 * service bits for this port.
1405 static int stli_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
1407 cdkasy_t __iomem
*ap
;
1408 cdkhdr_t __iomem
*hdrp
;
1409 unsigned char __iomem
*bits
;
1410 unsigned char __iomem
*shbuf
;
1411 unsigned char *chbuf
;
1414 unsigned int len
, stlen
, head
, tail
, size
;
1415 unsigned long flags
;
1417 if (tty
== stli_txcooktty
)
1418 stli_flushchars(tty
);
1419 portp
= tty
->driver_data
;
1422 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
1424 brdp
= stli_brds
[portp
->brdnr
];
1427 chbuf
= (unsigned char *) buf
;
1430 * All data is now local, shove as much as possible into shared memory.
1432 spin_lock_irqsave(&brd_lock
, flags
);
1434 ap
= (cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
1435 head
= (unsigned int) readw(&ap
->txq
.head
);
1436 tail
= (unsigned int) readw(&ap
->txq
.tail
);
1437 if (tail
!= ((unsigned int) readw(&ap
->txq
.tail
)))
1438 tail
= (unsigned int) readw(&ap
->txq
.tail
);
1439 size
= portp
->txsize
;
1441 len
= size
- (head
- tail
) - 1;
1442 stlen
= size
- head
;
1444 len
= tail
- head
- 1;
1448 len
= MIN(len
, count
);
1450 shbuf
= (char __iomem
*) EBRDGETMEMPTR(brdp
, portp
->txoffset
);
1453 stlen
= MIN(len
, stlen
);
1454 memcpy_toio(shbuf
+ head
, chbuf
, stlen
);
1465 ap
= (cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
1466 writew(head
, &ap
->txq
.head
);
1467 if (test_bit(ST_TXBUSY
, &portp
->state
)) {
1468 if (readl(&ap
->changed
.data
) & DT_TXEMPTY
)
1469 writel(readl(&ap
->changed
.data
) & ~DT_TXEMPTY
, &ap
->changed
.data
);
1471 hdrp
= (cdkhdr_t __iomem
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
1472 bits
= ((unsigned char __iomem
*) hdrp
) + brdp
->slaveoffset
+
1474 writeb(readb(bits
) | portp
->portbit
, bits
);
1475 set_bit(ST_TXBUSY
, &portp
->state
);
1477 spin_unlock_irqrestore(&brd_lock
, flags
);
1482 /*****************************************************************************/
1485 * Output a single character. We put it into a temporary local buffer
1486 * (for speed) then write out that buffer when the flushchars routine
1487 * is called. There is a safety catch here so that if some other port
1488 * writes chars before the current buffer has been, then we write them
1489 * first them do the new ports.
1492 static void stli_putchar(struct tty_struct
*tty
, unsigned char ch
)
1494 if (tty
!= stli_txcooktty
) {
1495 if (stli_txcooktty
!= NULL
)
1496 stli_flushchars(stli_txcooktty
);
1497 stli_txcooktty
= tty
;
1500 stli_txcookbuf
[stli_txcooksize
++] = ch
;
1503 /*****************************************************************************/
1506 * Transfer characters from the local TX cooking buffer to the board.
1507 * We sort of ignore the tty that gets passed in here. We rely on the
1508 * info stored with the TX cook buffer to tell us which port to flush
1509 * the data on. In any case we clean out the TX cook buffer, for re-use
1513 static void stli_flushchars(struct tty_struct
*tty
)
1515 cdkhdr_t __iomem
*hdrp
;
1516 unsigned char __iomem
*bits
;
1517 cdkasy_t __iomem
*ap
;
1518 struct tty_struct
*cooktty
;
1521 unsigned int len
, stlen
, head
, tail
, size
, count
, cooksize
;
1523 unsigned char __iomem
*shbuf
;
1524 unsigned long flags
;
1526 cooksize
= stli_txcooksize
;
1527 cooktty
= stli_txcooktty
;
1528 stli_txcooksize
= 0;
1529 stli_txcookrealsize
= 0;
1530 stli_txcooktty
= NULL
;
1534 if (cooktty
== NULL
)
1541 portp
= tty
->driver_data
;
1544 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
1546 brdp
= stli_brds
[portp
->brdnr
];
1550 spin_lock_irqsave(&brd_lock
, flags
);
1553 ap
= (cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
1554 head
= (unsigned int) readw(&ap
->txq
.head
);
1555 tail
= (unsigned int) readw(&ap
->txq
.tail
);
1556 if (tail
!= ((unsigned int) readw(&ap
->txq
.tail
)))
1557 tail
= (unsigned int) readw(&ap
->txq
.tail
);
1558 size
= portp
->txsize
;
1560 len
= size
- (head
- tail
) - 1;
1561 stlen
= size
- head
;
1563 len
= tail
- head
- 1;
1567 len
= MIN(len
, cooksize
);
1569 shbuf
= EBRDGETMEMPTR(brdp
, portp
->txoffset
);
1570 buf
= stli_txcookbuf
;
1573 stlen
= MIN(len
, stlen
);
1574 memcpy_toio(shbuf
+ head
, buf
, stlen
);
1585 ap
= (cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
1586 writew(head
, &ap
->txq
.head
);
1588 if (test_bit(ST_TXBUSY
, &portp
->state
)) {
1589 if (readl(&ap
->changed
.data
) & DT_TXEMPTY
)
1590 writel(readl(&ap
->changed
.data
) & ~DT_TXEMPTY
, &ap
->changed
.data
);
1592 hdrp
= (cdkhdr_t __iomem
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
1593 bits
= ((unsigned char __iomem
*) hdrp
) + brdp
->slaveoffset
+
1595 writeb(readb(bits
) | portp
->portbit
, bits
);
1596 set_bit(ST_TXBUSY
, &portp
->state
);
1599 spin_unlock_irqrestore(&brd_lock
, flags
);
1602 /*****************************************************************************/
1604 static int stli_writeroom(struct tty_struct
*tty
)
1606 cdkasyrq_t __iomem
*rp
;
1609 unsigned int head
, tail
, len
;
1610 unsigned long flags
;
1612 if (tty
== stli_txcooktty
) {
1613 if (stli_txcookrealsize
!= 0) {
1614 len
= stli_txcookrealsize
- stli_txcooksize
;
1619 portp
= tty
->driver_data
;
1622 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
1624 brdp
= stli_brds
[portp
->brdnr
];
1628 spin_lock_irqsave(&brd_lock
, flags
);
1630 rp
= &((cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->txq
;
1631 head
= (unsigned int) readw(&rp
->head
);
1632 tail
= (unsigned int) readw(&rp
->tail
);
1633 if (tail
!= ((unsigned int) readw(&rp
->tail
)))
1634 tail
= (unsigned int) readw(&rp
->tail
);
1635 len
= (head
>= tail
) ? (portp
->txsize
- (head
- tail
)) : (tail
- head
);
1638 spin_unlock_irqrestore(&brd_lock
, flags
);
1640 if (tty
== stli_txcooktty
) {
1641 stli_txcookrealsize
= len
;
1642 len
-= stli_txcooksize
;
1647 /*****************************************************************************/
1650 * Return the number of characters in the transmit buffer. Normally we
1651 * will return the number of chars in the shared memory ring queue.
1652 * We need to kludge around the case where the shared memory buffer is
1653 * empty but not all characters have drained yet, for this case just
1654 * return that there is 1 character in the buffer!
1657 static int stli_charsinbuffer(struct tty_struct
*tty
)
1659 cdkasyrq_t __iomem
*rp
;
1662 unsigned int head
, tail
, len
;
1663 unsigned long flags
;
1665 if (tty
== stli_txcooktty
)
1666 stli_flushchars(tty
);
1667 portp
= tty
->driver_data
;
1670 if ((portp
->brdnr
< 0) || (portp
->brdnr
>= stli_nrbrds
))
1672 brdp
= stli_brds
[portp
->brdnr
];
1676 spin_lock_irqsave(&brd_lock
, flags
);
1678 rp
= &((cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->txq
;
1679 head
= (unsigned int) readw(&rp
->head
);
1680 tail
= (unsigned int) readw(&rp
->tail
);
1681 if (tail
!= ((unsigned int) readw(&rp
->tail
)))
1682 tail
= (unsigned int) readw(&rp
->tail
);
1683 len
= (head
>= tail
) ? (head
- tail
) : (portp
->txsize
- (tail
- head
));
1684 if ((len
== 0) && test_bit(ST_TXBUSY
, &portp
->state
))
1687 spin_unlock_irqrestore(&brd_lock
, flags
);
1692 /*****************************************************************************/
1695 * Generate the serial struct info.
1698 static int stli_getserial(stliport_t
*portp
, struct serial_struct __user
*sp
)
1700 struct serial_struct sio
;
1703 memset(&sio
, 0, sizeof(struct serial_struct
));
1704 sio
.type
= PORT_UNKNOWN
;
1705 sio
.line
= portp
->portnr
;
1707 sio
.flags
= portp
->flags
;
1708 sio
.baud_base
= portp
->baud_base
;
1709 sio
.close_delay
= portp
->close_delay
;
1710 sio
.closing_wait
= portp
->closing_wait
;
1711 sio
.custom_divisor
= portp
->custom_divisor
;
1712 sio
.xmit_fifo_size
= 0;
1715 brdp
= stli_brds
[portp
->brdnr
];
1717 sio
.port
= brdp
->iobase
;
1719 return copy_to_user(sp
, &sio
, sizeof(struct serial_struct
)) ?
1723 /*****************************************************************************/
1726 * Set port according to the serial struct info.
1727 * At this point we do not do any auto-configure stuff, so we will
1728 * just quietly ignore any requests to change irq, etc.
1731 static int stli_setserial(stliport_t
*portp
, struct serial_struct __user
*sp
)
1733 struct serial_struct sio
;
1736 if (copy_from_user(&sio
, sp
, sizeof(struct serial_struct
)))
1738 if (!capable(CAP_SYS_ADMIN
)) {
1739 if ((sio
.baud_base
!= portp
->baud_base
) ||
1740 (sio
.close_delay
!= portp
->close_delay
) ||
1741 ((sio
.flags
& ~ASYNC_USR_MASK
) !=
1742 (portp
->flags
& ~ASYNC_USR_MASK
)))
1746 portp
->flags
= (portp
->flags
& ~ASYNC_USR_MASK
) |
1747 (sio
.flags
& ASYNC_USR_MASK
);
1748 portp
->baud_base
= sio
.baud_base
;
1749 portp
->close_delay
= sio
.close_delay
;
1750 portp
->closing_wait
= sio
.closing_wait
;
1751 portp
->custom_divisor
= sio
.custom_divisor
;
1753 if ((rc
= stli_setport(portp
)) < 0)
1758 /*****************************************************************************/
1760 static int stli_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1762 stliport_t
*portp
= tty
->driver_data
;
1768 if (portp
->brdnr
< 0 || portp
->brdnr
>= stli_nrbrds
)
1770 brdp
= stli_brds
[portp
->brdnr
];
1773 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1776 if ((rc
= stli_cmdwait(brdp
, portp
, A_GETSIGNALS
,
1777 &portp
->asig
, sizeof(asysigs_t
), 1)) < 0)
1780 return stli_mktiocm(portp
->asig
.sigvalue
);
1783 static int stli_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1784 unsigned int set
, unsigned int clear
)
1786 stliport_t
*portp
= tty
->driver_data
;
1788 int rts
= -1, dtr
= -1;
1792 if (portp
->brdnr
< 0 || portp
->brdnr
>= stli_nrbrds
)
1794 brdp
= stli_brds
[portp
->brdnr
];
1797 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1800 if (set
& TIOCM_RTS
)
1802 if (set
& TIOCM_DTR
)
1804 if (clear
& TIOCM_RTS
)
1806 if (clear
& TIOCM_DTR
)
1809 stli_mkasysigs(&portp
->asig
, dtr
, rts
);
1811 return stli_cmdwait(brdp
, portp
, A_SETSIGNALS
, &portp
->asig
,
1812 sizeof(asysigs_t
), 0);
1815 static int stli_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1821 void __user
*argp
= (void __user
*)arg
;
1823 portp
= tty
->driver_data
;
1826 if (portp
->brdnr
< 0 || portp
->brdnr
>= stli_nrbrds
)
1828 brdp
= stli_brds
[portp
->brdnr
];
1832 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1833 (cmd
!= COM_GETPORTSTATS
) && (cmd
!= COM_CLRPORTSTATS
)) {
1834 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1842 rc
= put_user(((tty
->termios
->c_cflag
& CLOCAL
) ? 1 : 0),
1843 (unsigned __user
*) arg
);
1846 if ((rc
= get_user(ival
, (unsigned __user
*) arg
)) == 0)
1847 tty
->termios
->c_cflag
=
1848 (tty
->termios
->c_cflag
& ~CLOCAL
) |
1849 (ival
? CLOCAL
: 0);
1852 rc
= stli_getserial(portp
, argp
);
1855 rc
= stli_setserial(portp
, argp
);
1858 rc
= put_user(portp
->pflag
, (unsigned __user
*)argp
);
1861 if ((rc
= get_user(portp
->pflag
, (unsigned __user
*)argp
)) == 0)
1862 stli_setport(portp
);
1864 case COM_GETPORTSTATS
:
1865 rc
= stli_getportstats(portp
, argp
);
1867 case COM_CLRPORTSTATS
:
1868 rc
= stli_clrportstats(portp
, argp
);
1874 case TIOCSERGSTRUCT
:
1875 case TIOCSERGETMULTI
:
1876 case TIOCSERSETMULTI
:
1885 /*****************************************************************************/
1888 * This routine assumes that we have user context and can sleep.
1889 * Looks like it is true for the current ttys implementation..!!
1892 static void stli_settermios(struct tty_struct
*tty
, struct termios
*old
)
1896 struct termios
*tiosp
;
1901 portp
= tty
->driver_data
;
1904 if (portp
->brdnr
< 0 || portp
->brdnr
>= stli_nrbrds
)
1906 brdp
= stli_brds
[portp
->brdnr
];
1910 tiosp
= tty
->termios
;
1911 if ((tiosp
->c_cflag
== old
->c_cflag
) &&
1912 (tiosp
->c_iflag
== old
->c_iflag
))
1915 stli_mkasyport(portp
, &aport
, tiosp
);
1916 stli_cmdwait(brdp
, portp
, A_SETPORT
, &aport
, sizeof(asyport_t
), 0);
1917 stli_mkasysigs(&portp
->asig
, ((tiosp
->c_cflag
& CBAUD
) ? 1 : 0), -1);
1918 stli_cmdwait(brdp
, portp
, A_SETSIGNALS
, &portp
->asig
,
1919 sizeof(asysigs_t
), 0);
1920 if ((old
->c_cflag
& CRTSCTS
) && ((tiosp
->c_cflag
& CRTSCTS
) == 0))
1921 tty
->hw_stopped
= 0;
1922 if (((old
->c_cflag
& CLOCAL
) == 0) && (tiosp
->c_cflag
& CLOCAL
))
1923 wake_up_interruptible(&portp
->open_wait
);
1926 /*****************************************************************************/
1929 * Attempt to flow control who ever is sending us data. We won't really
1930 * do any flow control action here. We can't directly, and even if we
1931 * wanted to we would have to send a command to the slave. The slave
1932 * knows how to flow control, and will do so when its buffers reach its
1933 * internal high water marks. So what we will do is set a local state
1934 * bit that will stop us sending any RX data up from the poll routine
1935 * (which is the place where RX data from the slave is handled).
1938 static void stli_throttle(struct tty_struct
*tty
)
1940 stliport_t
*portp
= tty
->driver_data
;
1943 set_bit(ST_RXSTOP
, &portp
->state
);
1946 /*****************************************************************************/
1949 * Unflow control the device sending us data... That means that all
1950 * we have to do is clear the RXSTOP state bit. The next poll call
1951 * will then be able to pass the RX data back up.
1954 static void stli_unthrottle(struct tty_struct
*tty
)
1956 stliport_t
*portp
= tty
->driver_data
;
1959 clear_bit(ST_RXSTOP
, &portp
->state
);
1962 /*****************************************************************************/
1965 * Stop the transmitter.
1968 static void stli_stop(struct tty_struct
*tty
)
1972 /*****************************************************************************/
1975 * Start the transmitter again.
1978 static void stli_start(struct tty_struct
*tty
)
1982 /*****************************************************************************/
1985 * Scheduler called hang up routine. This is called from the scheduler,
1986 * not direct from the driver "poll" routine. We can't call it there
1987 * since the real local hangup code will enable/disable the board and
1988 * other things that we can't do while handling the poll. Much easier
1989 * to deal with it some time later (don't really care when, hangups
1990 * aren't that time critical).
1993 static void stli_dohangup(void *arg
)
1995 stliport_t
*portp
= (stliport_t
*) arg
;
1996 if (portp
->tty
!= NULL
) {
1997 tty_hangup(portp
->tty
);
2001 /*****************************************************************************/
2004 * Hangup this port. This is pretty much like closing the port, only
2005 * a little more brutal. No waiting for data to drain. Shutdown the
2006 * port and maybe drop signals. This is rather tricky really. We want
2007 * to close the port as well.
2010 static void stli_hangup(struct tty_struct
*tty
)
2014 unsigned long flags
;
2016 portp
= tty
->driver_data
;
2019 if (portp
->brdnr
< 0 || portp
->brdnr
>= stli_nrbrds
)
2021 brdp
= stli_brds
[portp
->brdnr
];
2025 portp
->flags
&= ~ASYNC_INITIALIZED
;
2027 if (!test_bit(ST_CLOSING
, &portp
->state
))
2028 stli_rawclose(brdp
, portp
, 0, 0);
2030 spin_lock_irqsave(&stli_lock
, flags
);
2031 if (tty
->termios
->c_cflag
& HUPCL
) {
2032 stli_mkasysigs(&portp
->asig
, 0, 0);
2033 if (test_bit(ST_CMDING
, &portp
->state
)) {
2034 set_bit(ST_DOSIGS
, &portp
->state
);
2035 set_bit(ST_DOFLUSHTX
, &portp
->state
);
2036 set_bit(ST_DOFLUSHRX
, &portp
->state
);
2038 stli_sendcmd(brdp
, portp
, A_SETSIGNALSF
,
2039 &portp
->asig
, sizeof(asysigs_t
), 0);
2043 clear_bit(ST_TXBUSY
, &portp
->state
);
2044 clear_bit(ST_RXSTOP
, &portp
->state
);
2045 set_bit(TTY_IO_ERROR
, &tty
->flags
);
2047 portp
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
2048 portp
->refcount
= 0;
2049 spin_unlock_irqrestore(&stli_lock
, flags
);
2051 wake_up_interruptible(&portp
->open_wait
);
2054 /*****************************************************************************/
2057 * Flush characters from the lower buffer. We may not have user context
2058 * so we cannot sleep waiting for it to complete. Also we need to check
2059 * if there is chars for this port in the TX cook buffer, and flush them
2063 static void stli_flushbuffer(struct tty_struct
*tty
)
2067 unsigned long ftype
, flags
;
2069 portp
= tty
->driver_data
;
2072 if (portp
->brdnr
< 0 || portp
->brdnr
>= stli_nrbrds
)
2074 brdp
= stli_brds
[portp
->brdnr
];
2078 spin_lock_irqsave(&brd_lock
, flags
);
2079 if (tty
== stli_txcooktty
) {
2080 stli_txcooktty
= NULL
;
2081 stli_txcooksize
= 0;
2082 stli_txcookrealsize
= 0;
2084 if (test_bit(ST_CMDING
, &portp
->state
)) {
2085 set_bit(ST_DOFLUSHTX
, &portp
->state
);
2088 if (test_bit(ST_DOFLUSHRX
, &portp
->state
)) {
2090 clear_bit(ST_DOFLUSHRX
, &portp
->state
);
2092 __stli_sendcmd(brdp
, portp
, A_FLUSH
, &ftype
, sizeof(u32
), 0);
2094 spin_unlock_irqrestore(&brd_lock
, flags
);
2098 /*****************************************************************************/
2100 static void stli_breakctl(struct tty_struct
*tty
, int state
)
2106 portp
= tty
->driver_data
;
2109 if (portp
->brdnr
< 0 || portp
->brdnr
>= stli_nrbrds
)
2111 brdp
= stli_brds
[portp
->brdnr
];
2115 arg
= (state
== -1) ? BREAKON
: BREAKOFF
;
2116 stli_cmdwait(brdp
, portp
, A_BREAK
, &arg
, sizeof(long), 0);
2119 /*****************************************************************************/
2121 static void stli_waituntilsent(struct tty_struct
*tty
, int timeout
)
2128 portp
= tty
->driver_data
;
2134 tend
= jiffies
+ timeout
;
2136 while (test_bit(ST_TXBUSY
, &portp
->state
)) {
2137 if (signal_pending(current
))
2139 msleep_interruptible(20);
2140 if (time_after_eq(jiffies
, tend
))
2145 /*****************************************************************************/
2147 static void stli_sendxchar(struct tty_struct
*tty
, char ch
)
2153 portp
= tty
->driver_data
;
2156 if (portp
->brdnr
< 0 || portp
->brdnr
>= stli_nrbrds
)
2158 brdp
= stli_brds
[portp
->brdnr
];
2162 memset(&actrl
, 0, sizeof(asyctrl_t
));
2163 if (ch
== STOP_CHAR(tty
)) {
2164 actrl
.rxctrl
= CT_STOPFLOW
;
2165 } else if (ch
== START_CHAR(tty
)) {
2166 actrl
.rxctrl
= CT_STARTFLOW
;
2168 actrl
.txctrl
= CT_SENDCHR
;
2171 stli_cmdwait(brdp
, portp
, A_PORTCTRL
, &actrl
, sizeof(asyctrl_t
), 0);
2174 /*****************************************************************************/
2179 * Format info for a specified port. The line is deliberately limited
2180 * to 80 characters. (If it is too long it will be truncated, if too
2181 * short then padded with spaces).
2184 static int stli_portinfo(stlibrd_t
*brdp
, stliport_t
*portp
, int portnr
, char *pos
)
2189 rc
= stli_portcmdstats(portp
);
2192 if (brdp
->state
& BST_STARTED
) {
2193 switch (stli_comstats
.hwid
) {
2194 case 0: uart
= "2681"; break;
2195 case 1: uart
= "SC26198"; break;
2196 default:uart
= "CD1400"; break;
2201 sp
+= sprintf(sp
, "%d: uart:%s ", portnr
, uart
);
2203 if ((brdp
->state
& BST_STARTED
) && (rc
>= 0)) {
2204 sp
+= sprintf(sp
, "tx:%d rx:%d", (int) stli_comstats
.txtotal
,
2205 (int) stli_comstats
.rxtotal
);
2207 if (stli_comstats
.rxframing
)
2208 sp
+= sprintf(sp
, " fe:%d",
2209 (int) stli_comstats
.rxframing
);
2210 if (stli_comstats
.rxparity
)
2211 sp
+= sprintf(sp
, " pe:%d",
2212 (int) stli_comstats
.rxparity
);
2213 if (stli_comstats
.rxbreaks
)
2214 sp
+= sprintf(sp
, " brk:%d",
2215 (int) stli_comstats
.rxbreaks
);
2216 if (stli_comstats
.rxoverrun
)
2217 sp
+= sprintf(sp
, " oe:%d",
2218 (int) stli_comstats
.rxoverrun
);
2220 cnt
= sprintf(sp
, "%s%s%s%s%s ",
2221 (stli_comstats
.signals
& TIOCM_RTS
) ? "|RTS" : "",
2222 (stli_comstats
.signals
& TIOCM_CTS
) ? "|CTS" : "",
2223 (stli_comstats
.signals
& TIOCM_DTR
) ? "|DTR" : "",
2224 (stli_comstats
.signals
& TIOCM_CD
) ? "|DCD" : "",
2225 (stli_comstats
.signals
& TIOCM_DSR
) ? "|DSR" : "");
2230 for (cnt
= (sp
- pos
); (cnt
< (MAXLINE
- 1)); cnt
++)
2233 pos
[(MAXLINE
- 2)] = '+';
2234 pos
[(MAXLINE
- 1)] = '\n';
2239 /*****************************************************************************/
2242 * Port info, read from the /proc file system.
2245 static int stli_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
2249 int brdnr
, portnr
, totalport
;
2258 pos
+= sprintf(pos
, "%s: version %s", stli_drvtitle
,
2260 while (pos
< (page
+ MAXLINE
- 1))
2267 * We scan through for each board, panel and port. The offset is
2268 * calculated on the fly, and irrelevant ports are skipped.
2270 for (brdnr
= 0; (brdnr
< stli_nrbrds
); brdnr
++) {
2271 brdp
= stli_brds
[brdnr
];
2274 if (brdp
->state
== 0)
2277 maxoff
= curoff
+ (brdp
->nrports
* MAXLINE
);
2278 if (off
>= maxoff
) {
2283 totalport
= brdnr
* STL_MAXPORTS
;
2284 for (portnr
= 0; (portnr
< brdp
->nrports
); portnr
++,
2286 portp
= brdp
->ports
[portnr
];
2289 if (off
>= (curoff
+= MAXLINE
))
2291 if ((pos
- page
+ MAXLINE
) > count
)
2293 pos
+= stli_portinfo(brdp
, portp
, totalport
, pos
);
2304 /*****************************************************************************/
2307 * Generic send command routine. This will send a message to the slave,
2308 * of the specified type with the specified argument. Must be very
2309 * careful of data that will be copied out from shared memory -
2310 * containing command results. The command completion is all done from
2311 * a poll routine that does not have user context. Therefore you cannot
2312 * copy back directly into user space, or to the kernel stack of a
2313 * process. This routine does not sleep, so can be called from anywhere.
2315 * The caller must hold the brd_lock (see also stli_sendcmd the usual
2319 static void __stli_sendcmd(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long cmd
, void *arg
, int size
, int copyback
)
2321 cdkhdr_t __iomem
*hdrp
;
2322 cdkctrl_t __iomem
*cp
;
2323 unsigned char __iomem
*bits
;
2324 unsigned long flags
;
2326 spin_lock_irqsave(&brd_lock
, flags
);
2328 if (test_bit(ST_CMDING
, &portp
->state
)) {
2329 printk(KERN_ERR
"STALLION: command already busy, cmd=%x!\n",
2331 spin_unlock_irqrestore(&brd_lock
, flags
);
2336 cp
= &((cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->ctrl
;
2338 memcpy_toio((void __iomem
*) &(cp
->args
[0]), arg
, size
);
2341 portp
->argsize
= size
;
2344 writel(0, &cp
->status
);
2345 writel(cmd
, &cp
->cmd
);
2346 hdrp
= (cdkhdr_t __iomem
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
2347 bits
= ((unsigned char __iomem
*) hdrp
) + brdp
->slaveoffset
+
2349 writeb(readb(bits
) | portp
->portbit
, bits
);
2350 set_bit(ST_CMDING
, &portp
->state
);
2352 spin_unlock_irqrestore(&brd_lock
, flags
);
2355 static void stli_sendcmd(stlibrd_t
*brdp
, stliport_t
*portp
, unsigned long cmd
, void *arg
, int size
, int copyback
)
2357 unsigned long flags
;
2359 spin_lock_irqsave(&brd_lock
, flags
);
2360 __stli_sendcmd(brdp
, portp
, cmd
, arg
, size
, copyback
);
2361 spin_unlock_irqrestore(&brd_lock
, flags
);
2364 /*****************************************************************************/
2367 * Read data from shared memory. This assumes that the shared memory
2368 * is enabled and that interrupts are off. Basically we just empty out
2369 * the shared memory buffer into the tty buffer. Must be careful to
2370 * handle the case where we fill up the tty buffer, but still have
2371 * more chars to unload.
2374 static void stli_read(stlibrd_t
*brdp
, stliport_t
*portp
)
2376 cdkasyrq_t __iomem
*rp
;
2377 char __iomem
*shbuf
;
2378 struct tty_struct
*tty
;
2379 unsigned int head
, tail
, size
;
2380 unsigned int len
, stlen
;
2382 if (test_bit(ST_RXSTOP
, &portp
->state
))
2388 rp
= &((cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->rxq
;
2389 head
= (unsigned int) readw(&rp
->head
);
2390 if (head
!= ((unsigned int) readw(&rp
->head
)))
2391 head
= (unsigned int) readw(&rp
->head
);
2392 tail
= (unsigned int) readw(&rp
->tail
);
2393 size
= portp
->rxsize
;
2398 len
= size
- (tail
- head
);
2399 stlen
= size
- tail
;
2402 len
= tty_buffer_request_room(tty
, len
);
2404 shbuf
= (char __iomem
*) EBRDGETMEMPTR(brdp
, portp
->rxoffset
);
2407 unsigned char *cptr
;
2409 stlen
= MIN(len
, stlen
);
2410 tty_prepare_flip_string(tty
, &cptr
, stlen
);
2411 memcpy_fromio(cptr
, shbuf
+ tail
, stlen
);
2419 rp
= &((cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
))->rxq
;
2420 writew(tail
, &rp
->tail
);
2423 set_bit(ST_RXING
, &portp
->state
);
2425 tty_schedule_flip(tty
);
2428 /*****************************************************************************/
2431 * Set up and carry out any delayed commands. There is only a small set
2432 * of slave commands that can be done "off-level". So it is not too
2433 * difficult to deal with them here.
2436 static void stli_dodelaycmd(stliport_t
*portp
, cdkctrl_t __iomem
*cp
)
2440 if (test_bit(ST_DOSIGS
, &portp
->state
)) {
2441 if (test_bit(ST_DOFLUSHTX
, &portp
->state
) &&
2442 test_bit(ST_DOFLUSHRX
, &portp
->state
))
2443 cmd
= A_SETSIGNALSF
;
2444 else if (test_bit(ST_DOFLUSHTX
, &portp
->state
))
2445 cmd
= A_SETSIGNALSFTX
;
2446 else if (test_bit(ST_DOFLUSHRX
, &portp
->state
))
2447 cmd
= A_SETSIGNALSFRX
;
2450 clear_bit(ST_DOFLUSHTX
, &portp
->state
);
2451 clear_bit(ST_DOFLUSHRX
, &portp
->state
);
2452 clear_bit(ST_DOSIGS
, &portp
->state
);
2453 memcpy_toio((void __iomem
*) &(cp
->args
[0]), (void *) &portp
->asig
,
2455 writel(0, &cp
->status
);
2456 writel(cmd
, &cp
->cmd
);
2457 set_bit(ST_CMDING
, &portp
->state
);
2458 } else if (test_bit(ST_DOFLUSHTX
, &portp
->state
) ||
2459 test_bit(ST_DOFLUSHRX
, &portp
->state
)) {
2460 cmd
= ((test_bit(ST_DOFLUSHTX
, &portp
->state
)) ? FLUSHTX
: 0);
2461 cmd
|= ((test_bit(ST_DOFLUSHRX
, &portp
->state
)) ? FLUSHRX
: 0);
2462 clear_bit(ST_DOFLUSHTX
, &portp
->state
);
2463 clear_bit(ST_DOFLUSHRX
, &portp
->state
);
2464 memcpy_toio((void __iomem
*) &(cp
->args
[0]), (void *) &cmd
, sizeof(int));
2465 writel(0, &cp
->status
);
2466 writel(A_FLUSH
, &cp
->cmd
);
2467 set_bit(ST_CMDING
, &portp
->state
);
2471 /*****************************************************************************/
2474 * Host command service checking. This handles commands or messages
2475 * coming from the slave to the host. Must have board shared memory
2476 * enabled and interrupts off when called. Notice that by servicing the
2477 * read data last we don't need to change the shared memory pointer
2478 * during processing (which is a slow IO operation).
2479 * Return value indicates if this port is still awaiting actions from
2480 * the slave (like open, command, or even TX data being sent). If 0
2481 * then port is still busy, otherwise no longer busy.
2484 static int stli_hostcmd(stlibrd_t
*brdp
, stliport_t
*portp
)
2486 cdkasy_t __iomem
*ap
;
2487 cdkctrl_t __iomem
*cp
;
2488 struct tty_struct
*tty
;
2490 unsigned long oldsigs
;
2493 ap
= (cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
2497 * Check if we are waiting for an open completion message.
2499 if (test_bit(ST_OPENING
, &portp
->state
)) {
2500 rc
= readl(&cp
->openarg
);
2501 if (readb(&cp
->open
) == 0 && rc
!= 0) {
2504 writel(0, &cp
->openarg
);
2506 clear_bit(ST_OPENING
, &portp
->state
);
2507 wake_up_interruptible(&portp
->raw_wait
);
2512 * Check if we are waiting for a close completion message.
2514 if (test_bit(ST_CLOSING
, &portp
->state
)) {
2515 rc
= (int) readl(&cp
->closearg
);
2516 if (readb(&cp
->close
) == 0 && rc
!= 0) {
2519 writel(0, &cp
->closearg
);
2521 clear_bit(ST_CLOSING
, &portp
->state
);
2522 wake_up_interruptible(&portp
->raw_wait
);
2527 * Check if we are waiting for a command completion message. We may
2528 * need to copy out the command results associated with this command.
2530 if (test_bit(ST_CMDING
, &portp
->state
)) {
2531 rc
= readl(&cp
->status
);
2532 if (readl(&cp
->cmd
) == 0 && rc
!= 0) {
2535 if (portp
->argp
!= NULL
) {
2536 memcpy_fromio(portp
->argp
, (void __iomem
*) &(cp
->args
[0]),
2540 writel(0, &cp
->status
);
2542 clear_bit(ST_CMDING
, &portp
->state
);
2543 stli_dodelaycmd(portp
, cp
);
2544 wake_up_interruptible(&portp
->raw_wait
);
2549 * Check for any notification messages ready. This includes lots of
2550 * different types of events - RX chars ready, RX break received,
2551 * TX data low or empty in the slave, modem signals changed state.
2560 if (nt
.signal
& SG_DCD
) {
2561 oldsigs
= portp
->sigs
;
2562 portp
->sigs
= stli_mktiocm(nt
.sigvalue
);
2563 clear_bit(ST_GETSIGS
, &portp
->state
);
2564 if ((portp
->sigs
& TIOCM_CD
) &&
2565 ((oldsigs
& TIOCM_CD
) == 0))
2566 wake_up_interruptible(&portp
->open_wait
);
2567 if ((oldsigs
& TIOCM_CD
) &&
2568 ((portp
->sigs
& TIOCM_CD
) == 0)) {
2569 if (portp
->flags
& ASYNC_CHECK_CD
) {
2571 schedule_work(&portp
->tqhangup
);
2576 if (nt
.data
& DT_TXEMPTY
)
2577 clear_bit(ST_TXBUSY
, &portp
->state
);
2578 if (nt
.data
& (DT_TXEMPTY
| DT_TXLOW
)) {
2582 wake_up_interruptible(&tty
->write_wait
);
2586 if ((nt
.data
& DT_RXBREAK
) && (portp
->rxmarkmsk
& BRKINT
)) {
2588 tty_insert_flip_char(tty
, 0, TTY_BREAK
);
2589 if (portp
->flags
& ASYNC_SAK
) {
2593 tty_schedule_flip(tty
);
2597 if (nt
.data
& DT_RXBUSY
) {
2599 stli_read(brdp
, portp
);
2604 * It might seem odd that we are checking for more RX chars here.
2605 * But, we need to handle the case where the tty buffer was previously
2606 * filled, but we had more characters to pass up. The slave will not
2607 * send any more RX notify messages until the RX buffer has been emptied.
2608 * But it will leave the service bits on (since the buffer is not empty).
2609 * So from here we can try to process more RX chars.
2611 if ((!donerx
) && test_bit(ST_RXING
, &portp
->state
)) {
2612 clear_bit(ST_RXING
, &portp
->state
);
2613 stli_read(brdp
, portp
);
2616 return((test_bit(ST_OPENING
, &portp
->state
) ||
2617 test_bit(ST_CLOSING
, &portp
->state
) ||
2618 test_bit(ST_CMDING
, &portp
->state
) ||
2619 test_bit(ST_TXBUSY
, &portp
->state
) ||
2620 test_bit(ST_RXING
, &portp
->state
)) ? 0 : 1);
2623 /*****************************************************************************/
2626 * Service all ports on a particular board. Assumes that the boards
2627 * shared memory is enabled, and that the page pointer is pointed
2628 * at the cdk header structure.
2631 static void stli_brdpoll(stlibrd_t
*brdp
, cdkhdr_t __iomem
*hdrp
)
2634 unsigned char hostbits
[(STL_MAXCHANS
/ 8) + 1];
2635 unsigned char slavebits
[(STL_MAXCHANS
/ 8) + 1];
2636 unsigned char __iomem
*slavep
;
2637 int bitpos
, bitat
, bitsize
;
2638 int channr
, nrdevs
, slavebitchange
;
2640 bitsize
= brdp
->bitsize
;
2641 nrdevs
= brdp
->nrdevs
;
2644 * Check if slave wants any service. Basically we try to do as
2645 * little work as possible here. There are 2 levels of service
2646 * bits. So if there is nothing to do we bail early. We check
2647 * 8 service bits at a time in the inner loop, so we can bypass
2648 * the lot if none of them want service.
2650 memcpy_fromio(&hostbits
[0], (((unsigned char __iomem
*) hdrp
) + brdp
->hostoffset
),
2653 memset(&slavebits
[0], 0, bitsize
);
2656 for (bitpos
= 0; (bitpos
< bitsize
); bitpos
++) {
2657 if (hostbits
[bitpos
] == 0)
2659 channr
= bitpos
* 8;
2660 for (bitat
= 0x1; (channr
< nrdevs
); channr
++, bitat
<<= 1) {
2661 if (hostbits
[bitpos
] & bitat
) {
2662 portp
= brdp
->ports
[(channr
- 1)];
2663 if (stli_hostcmd(brdp
, portp
)) {
2665 slavebits
[bitpos
] |= bitat
;
2672 * If any of the ports are no longer busy then update them in the
2673 * slave request bits. We need to do this after, since a host port
2674 * service may initiate more slave requests.
2676 if (slavebitchange
) {
2677 hdrp
= (cdkhdr_t __iomem
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
2678 slavep
= ((unsigned char __iomem
*) hdrp
) + brdp
->slaveoffset
;
2679 for (bitpos
= 0; (bitpos
< bitsize
); bitpos
++) {
2680 if (readb(slavebits
+ bitpos
))
2681 writeb(readb(slavep
+ bitpos
) & ~slavebits
[bitpos
], slavebits
+ bitpos
);
2686 /*****************************************************************************/
2689 * Driver poll routine. This routine polls the boards in use and passes
2690 * messages back up to host when necessary. This is actually very
2691 * CPU efficient, since we will always have the kernel poll clock, it
2692 * adds only a few cycles when idle (since board service can be
2693 * determined very easily), but when loaded generates no interrupts
2694 * (with their expensive associated context change).
2697 static void stli_poll(unsigned long arg
)
2699 cdkhdr_t __iomem
*hdrp
;
2703 stli_timerlist
.expires
= STLI_TIMEOUT
;
2704 add_timer(&stli_timerlist
);
2707 * Check each board and do any servicing required.
2709 for (brdnr
= 0; (brdnr
< stli_nrbrds
); brdnr
++) {
2710 brdp
= stli_brds
[brdnr
];
2713 if ((brdp
->state
& BST_STARTED
) == 0)
2716 spin_lock(&brd_lock
);
2718 hdrp
= (cdkhdr_t __iomem
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
2719 if (readb(&hdrp
->hostreq
))
2720 stli_brdpoll(brdp
, hdrp
);
2722 spin_unlock(&brd_lock
);
2726 /*****************************************************************************/
2729 * Translate the termios settings into the port setting structure of
2733 static void stli_mkasyport(stliport_t
*portp
, asyport_t
*pp
, struct termios
*tiosp
)
2735 memset(pp
, 0, sizeof(asyport_t
));
2738 * Start of by setting the baud, char size, parity and stop bit info.
2740 pp
->baudout
= tty_get_baud_rate(portp
->tty
);
2741 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
2742 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
2743 pp
->baudout
= 57600;
2744 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
2745 pp
->baudout
= 115200;
2746 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
2747 pp
->baudout
= 230400;
2748 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
2749 pp
->baudout
= 460800;
2750 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
2751 pp
->baudout
= (portp
->baud_base
/ portp
->custom_divisor
);
2753 if (pp
->baudout
> STL_MAXBAUD
)
2754 pp
->baudout
= STL_MAXBAUD
;
2755 pp
->baudin
= pp
->baudout
;
2757 switch (tiosp
->c_cflag
& CSIZE
) {
2772 if (tiosp
->c_cflag
& CSTOPB
)
2773 pp
->stopbs
= PT_STOP2
;
2775 pp
->stopbs
= PT_STOP1
;
2777 if (tiosp
->c_cflag
& PARENB
) {
2778 if (tiosp
->c_cflag
& PARODD
)
2779 pp
->parity
= PT_ODDPARITY
;
2781 pp
->parity
= PT_EVENPARITY
;
2783 pp
->parity
= PT_NOPARITY
;
2787 * Set up any flow control options enabled.
2789 if (tiosp
->c_iflag
& IXON
) {
2791 if (tiosp
->c_iflag
& IXANY
)
2792 pp
->flow
|= F_IXANY
;
2794 if (tiosp
->c_cflag
& CRTSCTS
)
2795 pp
->flow
|= (F_RTSFLOW
| F_CTSFLOW
);
2797 pp
->startin
= tiosp
->c_cc
[VSTART
];
2798 pp
->stopin
= tiosp
->c_cc
[VSTOP
];
2799 pp
->startout
= tiosp
->c_cc
[VSTART
];
2800 pp
->stopout
= tiosp
->c_cc
[VSTOP
];
2803 * Set up the RX char marking mask with those RX error types we must
2804 * catch. We can get the slave to help us out a little here, it will
2805 * ignore parity errors and breaks for us, and mark parity errors in
2808 if (tiosp
->c_iflag
& IGNPAR
)
2809 pp
->iflag
|= FI_IGNRXERRS
;
2810 if (tiosp
->c_iflag
& IGNBRK
)
2811 pp
->iflag
|= FI_IGNBREAK
;
2813 portp
->rxmarkmsk
= 0;
2814 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
2815 pp
->iflag
|= FI_1MARKRXERRS
;
2816 if (tiosp
->c_iflag
& BRKINT
)
2817 portp
->rxmarkmsk
|= BRKINT
;
2820 * Set up clocal processing as required.
2822 if (tiosp
->c_cflag
& CLOCAL
)
2823 portp
->flags
&= ~ASYNC_CHECK_CD
;
2825 portp
->flags
|= ASYNC_CHECK_CD
;
2828 * Transfer any persistent flags into the asyport structure.
2830 pp
->pflag
= (portp
->pflag
& 0xffff);
2831 pp
->vmin
= (portp
->pflag
& P_RXIMIN
) ? 1 : 0;
2832 pp
->vtime
= (portp
->pflag
& P_RXITIME
) ? 1 : 0;
2833 pp
->cc
[1] = (portp
->pflag
& P_RXTHOLD
) ? 1 : 0;
2836 /*****************************************************************************/
2839 * Construct a slave signals structure for setting the DTR and RTS
2840 * signals as specified.
2843 static void stli_mkasysigs(asysigs_t
*sp
, int dtr
, int rts
)
2845 memset(sp
, 0, sizeof(asysigs_t
));
2847 sp
->signal
|= SG_DTR
;
2848 sp
->sigvalue
|= ((dtr
> 0) ? SG_DTR
: 0);
2851 sp
->signal
|= SG_RTS
;
2852 sp
->sigvalue
|= ((rts
> 0) ? SG_RTS
: 0);
2856 /*****************************************************************************/
2859 * Convert the signals returned from the slave into a local TIOCM type
2860 * signals value. We keep them locally in TIOCM format.
2863 static long stli_mktiocm(unsigned long sigvalue
)
2866 tiocm
|= ((sigvalue
& SG_DCD
) ? TIOCM_CD
: 0);
2867 tiocm
|= ((sigvalue
& SG_CTS
) ? TIOCM_CTS
: 0);
2868 tiocm
|= ((sigvalue
& SG_RI
) ? TIOCM_RI
: 0);
2869 tiocm
|= ((sigvalue
& SG_DSR
) ? TIOCM_DSR
: 0);
2870 tiocm
|= ((sigvalue
& SG_DTR
) ? TIOCM_DTR
: 0);
2871 tiocm
|= ((sigvalue
& SG_RTS
) ? TIOCM_RTS
: 0);
2875 /*****************************************************************************/
2878 * All panels and ports actually attached have been worked out. All
2879 * we need to do here is set up the appropriate per port data structures.
2882 static int stli_initports(stlibrd_t
*brdp
)
2885 int i
, panelnr
, panelport
;
2887 for (i
= 0, panelnr
= 0, panelport
= 0; (i
< brdp
->nrports
); i
++) {
2888 portp
= kzalloc(sizeof(stliport_t
), GFP_KERNEL
);
2890 printk("STALLION: failed to allocate port structure\n");
2894 portp
->magic
= STLI_PORTMAGIC
;
2896 portp
->brdnr
= brdp
->brdnr
;
2897 portp
->panelnr
= panelnr
;
2898 portp
->baud_base
= STL_BAUDBASE
;
2899 portp
->close_delay
= STL_CLOSEDELAY
;
2900 portp
->closing_wait
= 30 * HZ
;
2901 INIT_WORK(&portp
->tqhangup
, stli_dohangup
, portp
);
2902 init_waitqueue_head(&portp
->open_wait
);
2903 init_waitqueue_head(&portp
->close_wait
);
2904 init_waitqueue_head(&portp
->raw_wait
);
2906 if (panelport
>= brdp
->panels
[panelnr
]) {
2910 brdp
->ports
[i
] = portp
;
2916 /*****************************************************************************/
2919 * All the following routines are board specific hardware operations.
2922 static void stli_ecpinit(stlibrd_t
*brdp
)
2924 unsigned long memconf
;
2926 outb(ECP_ATSTOP
, (brdp
->iobase
+ ECP_ATCONFR
));
2928 outb(ECP_ATDISABLE
, (brdp
->iobase
+ ECP_ATCONFR
));
2931 memconf
= (brdp
->memaddr
& ECP_ATADDRMASK
) >> ECP_ATADDRSHFT
;
2932 outb(memconf
, (brdp
->iobase
+ ECP_ATMEMAR
));
2935 /*****************************************************************************/
2937 static void stli_ecpenable(stlibrd_t
*brdp
)
2939 outb(ECP_ATENABLE
, (brdp
->iobase
+ ECP_ATCONFR
));
2942 /*****************************************************************************/
2944 static void stli_ecpdisable(stlibrd_t
*brdp
)
2946 outb(ECP_ATDISABLE
, (brdp
->iobase
+ ECP_ATCONFR
));
2949 /*****************************************************************************/
2951 static void __iomem
*stli_ecpgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
2956 if (offset
> brdp
->memsize
) {
2957 printk(KERN_ERR
"STALLION: shared memory pointer=%x out of "
2958 "range at line=%d(%d), brd=%d\n",
2959 (int) offset
, line
, __LINE__
, brdp
->brdnr
);
2963 ptr
= brdp
->membase
+ (offset
% ECP_ATPAGESIZE
);
2964 val
= (unsigned char) (offset
/ ECP_ATPAGESIZE
);
2966 outb(val
, (brdp
->iobase
+ ECP_ATMEMPR
));
2970 /*****************************************************************************/
2972 static void stli_ecpreset(stlibrd_t
*brdp
)
2974 outb(ECP_ATSTOP
, (brdp
->iobase
+ ECP_ATCONFR
));
2976 outb(ECP_ATDISABLE
, (brdp
->iobase
+ ECP_ATCONFR
));
2980 /*****************************************************************************/
2982 static void stli_ecpintr(stlibrd_t
*brdp
)
2984 outb(0x1, brdp
->iobase
);
2987 /*****************************************************************************/
2990 * The following set of functions act on ECP EISA boards.
2993 static void stli_ecpeiinit(stlibrd_t
*brdp
)
2995 unsigned long memconf
;
2997 outb(0x1, (brdp
->iobase
+ ECP_EIBRDENAB
));
2998 outb(ECP_EISTOP
, (brdp
->iobase
+ ECP_EICONFR
));
3000 outb(ECP_EIDISABLE
, (brdp
->iobase
+ ECP_EICONFR
));
3003 memconf
= (brdp
->memaddr
& ECP_EIADDRMASKL
) >> ECP_EIADDRSHFTL
;
3004 outb(memconf
, (brdp
->iobase
+ ECP_EIMEMARL
));
3005 memconf
= (brdp
->memaddr
& ECP_EIADDRMASKH
) >> ECP_EIADDRSHFTH
;
3006 outb(memconf
, (brdp
->iobase
+ ECP_EIMEMARH
));
3009 /*****************************************************************************/
3011 static void stli_ecpeienable(stlibrd_t
*brdp
)
3013 outb(ECP_EIENABLE
, (brdp
->iobase
+ ECP_EICONFR
));
3016 /*****************************************************************************/
3018 static void stli_ecpeidisable(stlibrd_t
*brdp
)
3020 outb(ECP_EIDISABLE
, (brdp
->iobase
+ ECP_EICONFR
));
3023 /*****************************************************************************/
3025 static void __iomem
*stli_ecpeigetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3030 if (offset
> brdp
->memsize
) {
3031 printk(KERN_ERR
"STALLION: shared memory pointer=%x out of "
3032 "range at line=%d(%d), brd=%d\n",
3033 (int) offset
, line
, __LINE__
, brdp
->brdnr
);
3037 ptr
= brdp
->membase
+ (offset
% ECP_EIPAGESIZE
);
3038 if (offset
< ECP_EIPAGESIZE
)
3041 val
= ECP_EIENABLE
| 0x40;
3043 outb(val
, (brdp
->iobase
+ ECP_EICONFR
));
3047 /*****************************************************************************/
3049 static void stli_ecpeireset(stlibrd_t
*brdp
)
3051 outb(ECP_EISTOP
, (brdp
->iobase
+ ECP_EICONFR
));
3053 outb(ECP_EIDISABLE
, (brdp
->iobase
+ ECP_EICONFR
));
3057 /*****************************************************************************/
3060 * The following set of functions act on ECP MCA boards.
3063 static void stli_ecpmcenable(stlibrd_t
*brdp
)
3065 outb(ECP_MCENABLE
, (brdp
->iobase
+ ECP_MCCONFR
));
3068 /*****************************************************************************/
3070 static void stli_ecpmcdisable(stlibrd_t
*brdp
)
3072 outb(ECP_MCDISABLE
, (brdp
->iobase
+ ECP_MCCONFR
));
3075 /*****************************************************************************/
3077 static void __iomem
*stli_ecpmcgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3082 if (offset
> brdp
->memsize
) {
3083 printk(KERN_ERR
"STALLION: shared memory pointer=%x out of "
3084 "range at line=%d(%d), brd=%d\n",
3085 (int) offset
, line
, __LINE__
, brdp
->brdnr
);
3089 ptr
= brdp
->membase
+ (offset
% ECP_MCPAGESIZE
);
3090 val
= ((unsigned char) (offset
/ ECP_MCPAGESIZE
)) | ECP_MCENABLE
;
3092 outb(val
, (brdp
->iobase
+ ECP_MCCONFR
));
3096 /*****************************************************************************/
3098 static void stli_ecpmcreset(stlibrd_t
*brdp
)
3100 outb(ECP_MCSTOP
, (brdp
->iobase
+ ECP_MCCONFR
));
3102 outb(ECP_MCDISABLE
, (brdp
->iobase
+ ECP_MCCONFR
));
3106 /*****************************************************************************/
3109 * The following set of functions act on ECP PCI boards.
3112 static void stli_ecppciinit(stlibrd_t
*brdp
)
3114 outb(ECP_PCISTOP
, (brdp
->iobase
+ ECP_PCICONFR
));
3116 outb(0, (brdp
->iobase
+ ECP_PCICONFR
));
3120 /*****************************************************************************/
3122 static void __iomem
*stli_ecppcigetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3127 if (offset
> brdp
->memsize
) {
3128 printk(KERN_ERR
"STALLION: shared memory pointer=%x out of "
3129 "range at line=%d(%d), board=%d\n",
3130 (int) offset
, line
, __LINE__
, brdp
->brdnr
);
3134 ptr
= brdp
->membase
+ (offset
% ECP_PCIPAGESIZE
);
3135 val
= (offset
/ ECP_PCIPAGESIZE
) << 1;
3137 outb(val
, (brdp
->iobase
+ ECP_PCICONFR
));
3141 /*****************************************************************************/
3143 static void stli_ecppcireset(stlibrd_t
*brdp
)
3145 outb(ECP_PCISTOP
, (brdp
->iobase
+ ECP_PCICONFR
));
3147 outb(0, (brdp
->iobase
+ ECP_PCICONFR
));
3151 /*****************************************************************************/
3154 * The following routines act on ONboards.
3157 static void stli_onbinit(stlibrd_t
*brdp
)
3159 unsigned long memconf
;
3161 outb(ONB_ATSTOP
, (brdp
->iobase
+ ONB_ATCONFR
));
3163 outb(ONB_ATDISABLE
, (brdp
->iobase
+ ONB_ATCONFR
));
3166 memconf
= (brdp
->memaddr
& ONB_ATADDRMASK
) >> ONB_ATADDRSHFT
;
3167 outb(memconf
, (brdp
->iobase
+ ONB_ATMEMAR
));
3168 outb(0x1, brdp
->iobase
);
3172 /*****************************************************************************/
3174 static void stli_onbenable(stlibrd_t
*brdp
)
3176 outb((brdp
->enabval
| ONB_ATENABLE
), (brdp
->iobase
+ ONB_ATCONFR
));
3179 /*****************************************************************************/
3181 static void stli_onbdisable(stlibrd_t
*brdp
)
3183 outb((brdp
->enabval
| ONB_ATDISABLE
), (brdp
->iobase
+ ONB_ATCONFR
));
3186 /*****************************************************************************/
3188 static void __iomem
*stli_onbgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3192 if (offset
> brdp
->memsize
) {
3193 printk(KERN_ERR
"STALLION: shared memory pointer=%x out of "
3194 "range at line=%d(%d), brd=%d\n",
3195 (int) offset
, line
, __LINE__
, brdp
->brdnr
);
3198 ptr
= brdp
->membase
+ (offset
% ONB_ATPAGESIZE
);
3203 /*****************************************************************************/
3205 static void stli_onbreset(stlibrd_t
*brdp
)
3207 outb(ONB_ATSTOP
, (brdp
->iobase
+ ONB_ATCONFR
));
3209 outb(ONB_ATDISABLE
, (brdp
->iobase
+ ONB_ATCONFR
));
3213 /*****************************************************************************/
3216 * The following routines act on ONboard EISA.
3219 static void stli_onbeinit(stlibrd_t
*brdp
)
3221 unsigned long memconf
;
3223 outb(0x1, (brdp
->iobase
+ ONB_EIBRDENAB
));
3224 outb(ONB_EISTOP
, (brdp
->iobase
+ ONB_EICONFR
));
3226 outb(ONB_EIDISABLE
, (brdp
->iobase
+ ONB_EICONFR
));
3229 memconf
= (brdp
->memaddr
& ONB_EIADDRMASKL
) >> ONB_EIADDRSHFTL
;
3230 outb(memconf
, (brdp
->iobase
+ ONB_EIMEMARL
));
3231 memconf
= (brdp
->memaddr
& ONB_EIADDRMASKH
) >> ONB_EIADDRSHFTH
;
3232 outb(memconf
, (brdp
->iobase
+ ONB_EIMEMARH
));
3233 outb(0x1, brdp
->iobase
);
3237 /*****************************************************************************/
3239 static void stli_onbeenable(stlibrd_t
*brdp
)
3241 outb(ONB_EIENABLE
, (brdp
->iobase
+ ONB_EICONFR
));
3244 /*****************************************************************************/
3246 static void stli_onbedisable(stlibrd_t
*brdp
)
3248 outb(ONB_EIDISABLE
, (brdp
->iobase
+ ONB_EICONFR
));
3251 /*****************************************************************************/
3253 static void __iomem
*stli_onbegetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3258 if (offset
> brdp
->memsize
) {
3259 printk(KERN_ERR
"STALLION: shared memory pointer=%x out of "
3260 "range at line=%d(%d), brd=%d\n",
3261 (int) offset
, line
, __LINE__
, brdp
->brdnr
);
3265 ptr
= brdp
->membase
+ (offset
% ONB_EIPAGESIZE
);
3266 if (offset
< ONB_EIPAGESIZE
)
3269 val
= ONB_EIENABLE
| 0x40;
3271 outb(val
, (brdp
->iobase
+ ONB_EICONFR
));
3275 /*****************************************************************************/
3277 static void stli_onbereset(stlibrd_t
*brdp
)
3279 outb(ONB_EISTOP
, (brdp
->iobase
+ ONB_EICONFR
));
3281 outb(ONB_EIDISABLE
, (brdp
->iobase
+ ONB_EICONFR
));
3285 /*****************************************************************************/
3288 * The following routines act on Brumby boards.
3291 static void stli_bbyinit(stlibrd_t
*brdp
)
3293 outb(BBY_ATSTOP
, (brdp
->iobase
+ BBY_ATCONFR
));
3295 outb(0, (brdp
->iobase
+ BBY_ATCONFR
));
3297 outb(0x1, brdp
->iobase
);
3301 /*****************************************************************************/
3303 static void __iomem
*stli_bbygetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3308 BUG_ON(offset
> brdp
->memsize
);
3310 ptr
= brdp
->membase
+ (offset
% BBY_PAGESIZE
);
3311 val
= (unsigned char) (offset
/ BBY_PAGESIZE
);
3312 outb(val
, (brdp
->iobase
+ BBY_ATCONFR
));
3316 /*****************************************************************************/
3318 static void stli_bbyreset(stlibrd_t
*brdp
)
3320 outb(BBY_ATSTOP
, (brdp
->iobase
+ BBY_ATCONFR
));
3322 outb(0, (brdp
->iobase
+ BBY_ATCONFR
));
3326 /*****************************************************************************/
3329 * The following routines act on original old Stallion boards.
3332 static void stli_stalinit(stlibrd_t
*brdp
)
3334 outb(0x1, brdp
->iobase
);
3338 /*****************************************************************************/
3340 static void __iomem
*stli_stalgetmemptr(stlibrd_t
*brdp
, unsigned long offset
, int line
)
3342 BUG_ON(offset
> brdp
->memsize
);
3343 return brdp
->membase
+ (offset
% STAL_PAGESIZE
);
3346 /*****************************************************************************/
3348 static void stli_stalreset(stlibrd_t
*brdp
)
3352 vecp
= (u32 __iomem
*) (brdp
->membase
+ 0x30);
3353 writel(0xffff0000, vecp
);
3354 outb(0, brdp
->iobase
);
3358 /*****************************************************************************/
3361 * Try to find an ECP board and initialize it. This handles only ECP
3365 static int stli_initecp(stlibrd_t
*brdp
)
3368 cdkecpsig_t __iomem
*sigsp
;
3369 unsigned int status
, nxtid
;
3371 int panelnr
, nrports
;
3373 if (!request_region(brdp
->iobase
, brdp
->iosize
, "istallion"))
3376 if ((brdp
->iobase
== 0) || (brdp
->memaddr
== 0))
3378 release_region(brdp
->iobase
, brdp
->iosize
);
3382 brdp
->iosize
= ECP_IOSIZE
;
3385 * Based on the specific board type setup the common vars to access
3386 * and enable shared memory. Set all board specific information now
3389 switch (brdp
->brdtype
) {
3391 brdp
->membase
= (void *) brdp
->memaddr
;
3392 brdp
->memsize
= ECP_MEMSIZE
;
3393 brdp
->pagesize
= ECP_ATPAGESIZE
;
3394 brdp
->init
= stli_ecpinit
;
3395 brdp
->enable
= stli_ecpenable
;
3396 brdp
->reenable
= stli_ecpenable
;
3397 brdp
->disable
= stli_ecpdisable
;
3398 brdp
->getmemptr
= stli_ecpgetmemptr
;
3399 brdp
->intr
= stli_ecpintr
;
3400 brdp
->reset
= stli_ecpreset
;
3401 name
= "serial(EC8/64)";
3405 brdp
->membase
= (void *) brdp
->memaddr
;
3406 brdp
->memsize
= ECP_MEMSIZE
;
3407 brdp
->pagesize
= ECP_EIPAGESIZE
;
3408 brdp
->init
= stli_ecpeiinit
;
3409 brdp
->enable
= stli_ecpeienable
;
3410 brdp
->reenable
= stli_ecpeienable
;
3411 brdp
->disable
= stli_ecpeidisable
;
3412 brdp
->getmemptr
= stli_ecpeigetmemptr
;
3413 brdp
->intr
= stli_ecpintr
;
3414 brdp
->reset
= stli_ecpeireset
;
3415 name
= "serial(EC8/64-EI)";
3419 brdp
->membase
= (void *) brdp
->memaddr
;
3420 brdp
->memsize
= ECP_MEMSIZE
;
3421 brdp
->pagesize
= ECP_MCPAGESIZE
;
3423 brdp
->enable
= stli_ecpmcenable
;
3424 brdp
->reenable
= stli_ecpmcenable
;
3425 brdp
->disable
= stli_ecpmcdisable
;
3426 brdp
->getmemptr
= stli_ecpmcgetmemptr
;
3427 brdp
->intr
= stli_ecpintr
;
3428 brdp
->reset
= stli_ecpmcreset
;
3429 name
= "serial(EC8/64-MCA)";
3433 brdp
->membase
= (void *) brdp
->memaddr
;
3434 brdp
->memsize
= ECP_PCIMEMSIZE
;
3435 brdp
->pagesize
= ECP_PCIPAGESIZE
;
3436 brdp
->init
= stli_ecppciinit
;
3437 brdp
->enable
= NULL
;
3438 brdp
->reenable
= NULL
;
3439 brdp
->disable
= NULL
;
3440 brdp
->getmemptr
= stli_ecppcigetmemptr
;
3441 brdp
->intr
= stli_ecpintr
;
3442 brdp
->reset
= stli_ecppcireset
;
3443 name
= "serial(EC/RA-PCI)";
3447 release_region(brdp
->iobase
, brdp
->iosize
);
3452 * The per-board operations structure is all set up, so now let's go
3453 * and get the board operational. Firstly initialize board configuration
3454 * registers. Set the memory mapping info so we can get at the boards
3459 brdp
->membase
= ioremap(brdp
->memaddr
, brdp
->memsize
);
3460 if (brdp
->membase
== NULL
)
3462 release_region(brdp
->iobase
, brdp
->iosize
);
3467 * Now that all specific code is set up, enable the shared memory and
3468 * look for the a signature area that will tell us exactly what board
3469 * this is, and what it is connected to it.
3472 sigsp
= (cdkecpsig_t __iomem
*) EBRDGETMEMPTR(brdp
, CDK_SIGADDR
);
3473 memcpy_fromio(&sig
, sigsp
, sizeof(cdkecpsig_t
));
3476 if (sig
.magic
!= cpu_to_le32(ECP_MAGIC
))
3478 release_region(brdp
->iobase
, brdp
->iosize
);
3483 * Scan through the signature looking at the panels connected to the
3484 * board. Calculate the total number of ports as we go.
3486 for (panelnr
= 0, nxtid
= 0; (panelnr
< STL_MAXPANELS
); panelnr
++) {
3487 status
= sig
.panelid
[nxtid
];
3488 if ((status
& ECH_PNLIDMASK
) != nxtid
)
3491 brdp
->panelids
[panelnr
] = status
;
3492 nrports
= (status
& ECH_PNL16PORT
) ? 16 : 8;
3493 if ((nrports
== 16) && ((status
& ECH_PNLXPID
) == 0))
3495 brdp
->panels
[panelnr
] = nrports
;
3496 brdp
->nrports
+= nrports
;
3502 brdp
->state
|= BST_FOUND
;
3506 /*****************************************************************************/
3509 * Try to find an ONboard, Brumby or Stallion board and initialize it.
3510 * This handles only these board types.
3513 static int stli_initonb(stlibrd_t
*brdp
)
3516 cdkonbsig_t __iomem
*sigsp
;
3521 * Do a basic sanity check on the IO and memory addresses.
3523 if (brdp
->iobase
== 0 || brdp
->memaddr
== 0)
3526 brdp
->iosize
= ONB_IOSIZE
;
3528 if (!request_region(brdp
->iobase
, brdp
->iosize
, "istallion"))
3532 * Based on the specific board type setup the common vars to access
3533 * and enable shared memory. Set all board specific information now
3536 switch (brdp
->brdtype
) {
3540 case BRD_ONBOARD2_32
:
3542 brdp
->memsize
= ONB_MEMSIZE
;
3543 brdp
->pagesize
= ONB_ATPAGESIZE
;
3544 brdp
->init
= stli_onbinit
;
3545 brdp
->enable
= stli_onbenable
;
3546 brdp
->reenable
= stli_onbenable
;
3547 brdp
->disable
= stli_onbdisable
;
3548 brdp
->getmemptr
= stli_onbgetmemptr
;
3549 brdp
->intr
= stli_ecpintr
;
3550 brdp
->reset
= stli_onbreset
;
3551 if (brdp
->memaddr
> 0x100000)
3552 brdp
->enabval
= ONB_MEMENABHI
;
3554 brdp
->enabval
= ONB_MEMENABLO
;
3555 name
= "serial(ONBoard)";
3559 brdp
->memsize
= ONB_EIMEMSIZE
;
3560 brdp
->pagesize
= ONB_EIPAGESIZE
;
3561 brdp
->init
= stli_onbeinit
;
3562 brdp
->enable
= stli_onbeenable
;
3563 brdp
->reenable
= stli_onbeenable
;
3564 brdp
->disable
= stli_onbedisable
;
3565 brdp
->getmemptr
= stli_onbegetmemptr
;
3566 brdp
->intr
= stli_ecpintr
;
3567 brdp
->reset
= stli_onbereset
;
3568 name
= "serial(ONBoard/E)";
3574 brdp
->memsize
= BBY_MEMSIZE
;
3575 brdp
->pagesize
= BBY_PAGESIZE
;
3576 brdp
->init
= stli_bbyinit
;
3577 brdp
->enable
= NULL
;
3578 brdp
->reenable
= NULL
;
3579 brdp
->disable
= NULL
;
3580 brdp
->getmemptr
= stli_bbygetmemptr
;
3581 brdp
->intr
= stli_ecpintr
;
3582 brdp
->reset
= stli_bbyreset
;
3583 name
= "serial(Brumby)";
3587 brdp
->memsize
= STAL_MEMSIZE
;
3588 brdp
->pagesize
= STAL_PAGESIZE
;
3589 brdp
->init
= stli_stalinit
;
3590 brdp
->enable
= NULL
;
3591 brdp
->reenable
= NULL
;
3592 brdp
->disable
= NULL
;
3593 brdp
->getmemptr
= stli_stalgetmemptr
;
3594 brdp
->intr
= stli_ecpintr
;
3595 brdp
->reset
= stli_stalreset
;
3596 name
= "serial(Stallion)";
3600 release_region(brdp
->iobase
, brdp
->iosize
);
3605 * The per-board operations structure is all set up, so now let's go
3606 * and get the board operational. Firstly initialize board configuration
3607 * registers. Set the memory mapping info so we can get at the boards
3612 brdp
->membase
= ioremap(brdp
->memaddr
, brdp
->memsize
);
3613 if (brdp
->membase
== NULL
)
3615 release_region(brdp
->iobase
, brdp
->iosize
);
3620 * Now that all specific code is set up, enable the shared memory and
3621 * look for the a signature area that will tell us exactly what board
3622 * this is, and how many ports.
3625 sigsp
= (cdkonbsig_t __iomem
*) EBRDGETMEMPTR(brdp
, CDK_SIGADDR
);
3626 memcpy_fromio(&sig
, sigsp
, sizeof(cdkonbsig_t
));
3629 if (sig
.magic0
!= cpu_to_le16(ONB_MAGIC0
) ||
3630 sig
.magic1
!= cpu_to_le16(ONB_MAGIC1
) ||
3631 sig
.magic2
!= cpu_to_le16(ONB_MAGIC2
) ||
3632 sig
.magic3
!= cpu_to_le16(ONB_MAGIC3
))
3634 release_region(brdp
->iobase
, brdp
->iosize
);
3639 * Scan through the signature alive mask and calculate how many ports
3640 * there are on this board.
3646 for (i
= 0; (i
< 16); i
++) {
3647 if (((sig
.amask0
<< i
) & 0x8000) == 0)
3652 brdp
->panels
[0] = brdp
->nrports
;
3655 brdp
->state
|= BST_FOUND
;
3659 /*****************************************************************************/
3662 * Start up a running board. This routine is only called after the
3663 * code has been down loaded to the board and is operational. It will
3664 * read in the memory map, and get the show on the road...
3667 static int stli_startbrd(stlibrd_t
*brdp
)
3669 cdkhdr_t __iomem
*hdrp
;
3670 cdkmem_t __iomem
*memp
;
3671 cdkasy_t __iomem
*ap
;
3672 unsigned long flags
;
3674 int portnr
, nrdevs
, i
, rc
= 0;
3677 spin_lock_irqsave(&brd_lock
, flags
);
3679 hdrp
= (cdkhdr_t __iomem
*) EBRDGETMEMPTR(brdp
, CDK_CDKADDR
);
3680 nrdevs
= hdrp
->nrdevs
;
3683 printk("%s(%d): CDK version %d.%d.%d --> "
3684 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
3685 __FILE__
, __LINE__
, readb(&hdrp
->ver_release
), readb(&hdrp
->ver_modification
),
3686 readb(&hdrp
->ver_fix
), nrdevs
, (int) readl(&hdrp
->memp
), readl(&hdrp
->hostp
),
3687 readl(&hdrp
->slavep
));
3690 if (nrdevs
< (brdp
->nrports
+ 1)) {
3691 printk(KERN_ERR
"STALLION: slave failed to allocate memory for "
3692 "all devices, devices=%d\n", nrdevs
);
3693 brdp
->nrports
= nrdevs
- 1;
3695 brdp
->nrdevs
= nrdevs
;
3696 brdp
->hostoffset
= hdrp
->hostp
- CDK_CDKADDR
;
3697 brdp
->slaveoffset
= hdrp
->slavep
- CDK_CDKADDR
;
3698 brdp
->bitsize
= (nrdevs
+ 7) / 8;
3699 memoff
= readl(&hdrp
->memp
);
3700 if (memoff
> brdp
->memsize
) {
3701 printk(KERN_ERR
"STALLION: corrupted shared memory region?\n");
3703 goto stli_donestartup
;
3705 memp
= (cdkmem_t __iomem
*) EBRDGETMEMPTR(brdp
, memoff
);
3706 if (readw(&memp
->dtype
) != TYP_ASYNCTRL
) {
3707 printk(KERN_ERR
"STALLION: no slave control device found\n");
3708 goto stli_donestartup
;
3713 * Cycle through memory allocation of each port. We are guaranteed to
3714 * have all ports inside the first page of slave window, so no need to
3715 * change pages while reading memory map.
3717 for (i
= 1, portnr
= 0; (i
< nrdevs
); i
++, portnr
++, memp
++) {
3718 if (readw(&memp
->dtype
) != TYP_ASYNC
)
3720 portp
= brdp
->ports
[portnr
];
3724 portp
->addr
= readl(&memp
->offset
);
3725 portp
->reqbit
= (unsigned char) (0x1 << (i
* 8 / nrdevs
));
3726 portp
->portidx
= (unsigned char) (i
/ 8);
3727 portp
->portbit
= (unsigned char) (0x1 << (i
% 8));
3730 writeb(0xff, &hdrp
->slavereq
);
3733 * For each port setup a local copy of the RX and TX buffer offsets
3734 * and sizes. We do this separate from the above, because we need to
3735 * move the shared memory page...
3737 for (i
= 1, portnr
= 0; (i
< nrdevs
); i
++, portnr
++) {
3738 portp
= brdp
->ports
[portnr
];
3741 if (portp
->addr
== 0)
3743 ap
= (cdkasy_t __iomem
*) EBRDGETMEMPTR(brdp
, portp
->addr
);
3745 portp
->rxsize
= readw(&ap
->rxq
.size
);
3746 portp
->txsize
= readw(&ap
->txq
.size
);
3747 portp
->rxoffset
= readl(&ap
->rxq
.offset
);
3748 portp
->txoffset
= readl(&ap
->txq
.offset
);
3754 spin_unlock_irqrestore(&brd_lock
, flags
);
3757 brdp
->state
|= BST_STARTED
;
3759 if (! stli_timeron
) {
3761 stli_timerlist
.expires
= STLI_TIMEOUT
;
3762 add_timer(&stli_timerlist
);
3768 /*****************************************************************************/
3771 * Probe and initialize the specified board.
3774 static int __init
stli_brdinit(stlibrd_t
*brdp
)
3776 stli_brds
[brdp
->brdnr
] = brdp
;
3778 switch (brdp
->brdtype
) {
3789 case BRD_ONBOARD2_32
:
3801 printk(KERN_ERR
"STALLION: %s board type not supported in "
3802 "this driver\n", stli_brdnames
[brdp
->brdtype
]);
3805 printk(KERN_ERR
"STALLION: board=%d is unknown board "
3806 "type=%d\n", brdp
->brdnr
, brdp
->brdtype
);
3810 if ((brdp
->state
& BST_FOUND
) == 0) {
3811 printk(KERN_ERR
"STALLION: %s board not found, board=%d "
3813 stli_brdnames
[brdp
->brdtype
], brdp
->brdnr
,
3814 brdp
->iobase
, (int) brdp
->memaddr
);
3818 stli_initports(brdp
);
3819 printk(KERN_INFO
"STALLION: %s found, board=%d io=%x mem=%x "
3820 "nrpanels=%d nrports=%d\n", stli_brdnames
[brdp
->brdtype
],
3821 brdp
->brdnr
, brdp
->iobase
, (int) brdp
->memaddr
,
3822 brdp
->nrpanels
, brdp
->nrports
);
3826 /*****************************************************************************/
3829 * Probe around trying to find where the EISA boards shared memory
3830 * might be. This is a bit if hack, but it is the best we can do.
3833 static int stli_eisamemprobe(stlibrd_t
*brdp
)
3835 cdkecpsig_t ecpsig
, __iomem
*ecpsigp
;
3836 cdkonbsig_t onbsig
, __iomem
*onbsigp
;
3840 * First up we reset the board, to get it into a known state. There
3841 * is only 2 board types here we need to worry about. Don;t use the
3842 * standard board init routine here, it programs up the shared
3843 * memory address, and we don't know it yet...
3845 if (brdp
->brdtype
== BRD_ECPE
) {
3846 outb(0x1, (brdp
->iobase
+ ECP_EIBRDENAB
));
3847 outb(ECP_EISTOP
, (brdp
->iobase
+ ECP_EICONFR
));
3849 outb(ECP_EIDISABLE
, (brdp
->iobase
+ ECP_EICONFR
));
3851 stli_ecpeienable(brdp
);
3852 } else if (brdp
->brdtype
== BRD_ONBOARDE
) {
3853 outb(0x1, (brdp
->iobase
+ ONB_EIBRDENAB
));
3854 outb(ONB_EISTOP
, (brdp
->iobase
+ ONB_EICONFR
));
3856 outb(ONB_EIDISABLE
, (brdp
->iobase
+ ONB_EICONFR
));
3858 outb(0x1, brdp
->iobase
);
3860 stli_onbeenable(brdp
);
3866 brdp
->memsize
= ECP_MEMSIZE
;
3869 * Board shared memory is enabled, so now we have a poke around and
3870 * see if we can find it.
3872 for (i
= 0; (i
< stli_eisamempsize
); i
++) {
3873 brdp
->memaddr
= stli_eisamemprobeaddrs
[i
];
3874 brdp
->membase
= ioremap(brdp
->memaddr
, brdp
->memsize
);
3875 if (brdp
->membase
== NULL
)
3878 if (brdp
->brdtype
== BRD_ECPE
) {
3879 ecpsigp
= stli_ecpeigetmemptr(brdp
,
3880 CDK_SIGADDR
, __LINE__
);
3881 memcpy_fromio(&ecpsig
, ecpsigp
, sizeof(cdkecpsig_t
));
3882 if (ecpsig
.magic
== cpu_to_le32(ECP_MAGIC
))
3885 onbsigp
= (cdkonbsig_t __iomem
*) stli_onbegetmemptr(brdp
,
3886 CDK_SIGADDR
, __LINE__
);
3887 memcpy_fromio(&onbsig
, onbsigp
, sizeof(cdkonbsig_t
));
3888 if ((onbsig
.magic0
== cpu_to_le16(ONB_MAGIC0
)) &&
3889 (onbsig
.magic1
== cpu_to_le16(ONB_MAGIC1
)) &&
3890 (onbsig
.magic2
== cpu_to_le16(ONB_MAGIC2
)) &&
3891 (onbsig
.magic3
== cpu_to_le16(ONB_MAGIC3
)))
3895 iounmap(brdp
->membase
);
3901 * Regardless of whether we found the shared memory or not we must
3902 * disable the region. After that return success or failure.
3904 if (brdp
->brdtype
== BRD_ECPE
)
3905 stli_ecpeidisable(brdp
);
3907 stli_onbedisable(brdp
);
3911 brdp
->membase
= NULL
;
3912 printk(KERN_ERR
"STALLION: failed to probe shared memory "
3913 "region for %s in EISA slot=%d\n",
3914 stli_brdnames
[brdp
->brdtype
], (brdp
->iobase
>> 12));
3920 static int stli_getbrdnr(void)
3924 for (i
= 0; i
< STL_MAXBRDS
; i
++) {
3925 if (!stli_brds
[i
]) {
3926 if (i
>= stli_nrbrds
)
3927 stli_nrbrds
= i
+ 1;
3934 /*****************************************************************************/
3937 * Probe around and try to find any EISA boards in system. The biggest
3938 * problem here is finding out what memory address is associated with
3939 * an EISA board after it is found. The registers of the ECPE and
3940 * ONboardE are not readable - so we can't read them from there. We
3941 * don't have access to the EISA CMOS (or EISA BIOS) so we don't
3942 * actually have any way to find out the real value. The best we can
3943 * do is go probing around in the usual places hoping we can find it.
3946 static int stli_findeisabrds(void)
3949 unsigned int iobase
, eid
;
3953 * Firstly check if this is an EISA system. If this is not an EISA system then
3954 * don't bother going any further!
3960 * Looks like an EISA system, so go searching for EISA boards.
3962 for (iobase
= 0x1000; (iobase
<= 0xc000); iobase
+= 0x1000) {
3963 outb(0xff, (iobase
+ 0xc80));
3964 eid
= inb(iobase
+ 0xc80);
3965 eid
|= inb(iobase
+ 0xc81) << 8;
3966 if (eid
!= STL_EISAID
)
3970 * We have found a board. Need to check if this board was
3971 * statically configured already (just in case!).
3973 for (i
= 0; (i
< STL_MAXBRDS
); i
++) {
3974 brdp
= stli_brds
[i
];
3977 if (brdp
->iobase
== iobase
)
3980 if (i
< STL_MAXBRDS
)
3984 * We have found a Stallion board and it is not configured already.
3985 * Allocate a board structure and initialize it.
3987 if ((brdp
= stli_allocbrd()) == NULL
)
3989 if ((brdp
->brdnr
= stli_getbrdnr()) < 0)
3991 eid
= inb(iobase
+ 0xc82);
3992 if (eid
== ECP_EISAID
)
3993 brdp
->brdtype
= BRD_ECPE
;
3994 else if (eid
== ONB_EISAID
)
3995 brdp
->brdtype
= BRD_ONBOARDE
;
3997 brdp
->brdtype
= BRD_UNKNOWN
;
3998 brdp
->iobase
= iobase
;
3999 outb(0x1, (iobase
+ 0xc84));
4000 if (stli_eisamemprobe(brdp
))
4001 outb(0, (iobase
+ 0xc84));
4008 /*****************************************************************************/
4011 * Find the next available board number that is free.
4014 /*****************************************************************************/
4019 * We have a Stallion board. Allocate a board structure and
4020 * initialize it. Read its IO and MEMORY resources from PCI
4021 * configuration space.
4024 static int stli_initpcibrd(int brdtype
, struct pci_dev
*devp
)
4028 if (pci_enable_device(devp
))
4030 if ((brdp
= stli_allocbrd()) == NULL
)
4032 if ((brdp
->brdnr
= stli_getbrdnr()) < 0) {
4033 printk(KERN_INFO
"STALLION: too many boards found, "
4034 "maximum supported %d\n", STL_MAXBRDS
);
4037 brdp
->brdtype
= brdtype
;
4039 * We have all resources from the board, so lets setup the actual
4040 * board structure now.
4042 brdp
->iobase
= pci_resource_start(devp
, 3);
4043 brdp
->memaddr
= pci_resource_start(devp
, 2);
4049 /*****************************************************************************/
4052 * Find all Stallion PCI boards that might be installed. Initialize each
4053 * one as it is found.
4056 static int stli_findpcibrds(void)
4058 struct pci_dev
*dev
= NULL
;
4060 while ((dev
= pci_get_device(PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECRA
, dev
))) {
4061 stli_initpcibrd(BRD_ECPPCI
, dev
);
4068 /*****************************************************************************/
4071 * Allocate a new board structure. Fill out the basic info in it.
4074 static stlibrd_t
*stli_allocbrd(void)
4078 brdp
= kzalloc(sizeof(stlibrd_t
), GFP_KERNEL
);
4080 printk(KERN_ERR
"STALLION: failed to allocate memory "
4081 "(size=%Zd)\n", sizeof(stlibrd_t
));
4084 brdp
->magic
= STLI_BOARDMAGIC
;
4088 /*****************************************************************************/
4091 * Scan through all the boards in the configuration and see what we
4095 static int stli_initbrds(void)
4097 stlibrd_t
*brdp
, *nxtbrdp
;
4101 if (stli_nrbrds
> STL_MAXBRDS
) {
4102 printk(KERN_INFO
"STALLION: too many boards in configuration "
4103 "table, truncating to %d\n", STL_MAXBRDS
);
4104 stli_nrbrds
= STL_MAXBRDS
;
4108 * Firstly scan the list of static boards configured. Allocate
4109 * resources and initialize the boards as found. If this is a
4110 * module then let the module args override static configuration.
4112 for (i
= 0; (i
< stli_nrbrds
); i
++) {
4113 confp
= &stli_brdconf
[i
];
4114 stli_parsebrd(confp
, stli_brdsp
[i
]);
4115 if ((brdp
= stli_allocbrd()) == NULL
)
4118 brdp
->brdtype
= confp
->brdtype
;
4119 brdp
->iobase
= confp
->ioaddr1
;
4120 brdp
->memaddr
= confp
->memaddr
;
4125 * Static configuration table done, so now use dynamic methods to
4126 * see if any more boards should be configured.
4130 stli_findeisabrds();
4136 * All found boards are initialized. Now for a little optimization, if
4137 * no boards are sharing the "shared memory" regions then we can just
4138 * leave them all enabled. This is in fact the usual case.
4141 if (stli_nrbrds
> 1) {
4142 for (i
= 0; (i
< stli_nrbrds
); i
++) {
4143 brdp
= stli_brds
[i
];
4146 for (j
= i
+ 1; (j
< stli_nrbrds
); j
++) {
4147 nxtbrdp
= stli_brds
[j
];
4148 if (nxtbrdp
== NULL
)
4150 if ((brdp
->membase
>= nxtbrdp
->membase
) &&
4151 (brdp
->membase
<= (nxtbrdp
->membase
+
4152 nxtbrdp
->memsize
- 1))) {
4160 if (stli_shared
== 0) {
4161 for (i
= 0; (i
< stli_nrbrds
); i
++) {
4162 brdp
= stli_brds
[i
];
4165 if (brdp
->state
& BST_FOUND
) {
4167 brdp
->enable
= NULL
;
4168 brdp
->disable
= NULL
;
4176 /*****************************************************************************/
4179 * Code to handle an "staliomem" read operation. This device is the
4180 * contents of the board shared memory. It is used for down loading
4181 * the slave image (and debugging :-)
4184 static ssize_t
stli_memread(struct file
*fp
, char __user
*buf
, size_t count
, loff_t
*offp
)
4186 unsigned long flags
;
4187 void __iomem
*memptr
;
4193 brdnr
= iminor(fp
->f_dentry
->d_inode
);
4194 if (brdnr
>= stli_nrbrds
)
4196 brdp
= stli_brds
[brdnr
];
4199 if (brdp
->state
== 0)
4201 if (off
>= brdp
->memsize
|| off
+ count
< off
)
4204 size
= MIN(count
, (brdp
->memsize
- off
));
4207 * Copy the data a page at a time
4210 p
= (void *)__get_free_page(GFP_KERNEL
);
4215 spin_lock_irqsave(&brd_lock
, flags
);
4217 memptr
= EBRDGETMEMPTR(brdp
, off
);
4218 n
= MIN(size
, (brdp
->pagesize
- (((unsigned long) off
) % brdp
->pagesize
)));
4219 n
= MIN(n
, PAGE_SIZE
);
4220 memcpy_fromio(p
, memptr
, n
);
4222 spin_unlock_irqrestore(&brd_lock
, flags
);
4223 if (copy_to_user(buf
, p
, n
)) {
4233 free_page((unsigned long)p
);
4237 /*****************************************************************************/
4240 * Code to handle an "staliomem" write operation. This device is the
4241 * contents of the board shared memory. It is used for down loading
4242 * the slave image (and debugging :-)
4244 * FIXME: copy under lock
4247 static ssize_t
stli_memwrite(struct file
*fp
, const char __user
*buf
, size_t count
, loff_t
*offp
)
4249 unsigned long flags
;
4250 void __iomem
*memptr
;
4257 brdnr
= iminor(fp
->f_dentry
->d_inode
);
4259 if (brdnr
>= stli_nrbrds
)
4261 brdp
= stli_brds
[brdnr
];
4264 if (brdp
->state
== 0)
4266 if (off
>= brdp
->memsize
|| off
+ count
< off
)
4269 chbuf
= (char __user
*) buf
;
4270 size
= MIN(count
, (brdp
->memsize
- off
));
4273 * Copy the data a page at a time
4276 p
= (void *)__get_free_page(GFP_KERNEL
);
4281 n
= MIN(size
, (brdp
->pagesize
- (((unsigned long) off
) % brdp
->pagesize
)));
4282 n
= MIN(n
, PAGE_SIZE
);
4283 if (copy_from_user(p
, chbuf
, n
)) {
4288 spin_lock_irqsave(&brd_lock
, flags
);
4290 memptr
= EBRDGETMEMPTR(brdp
, off
);
4291 memcpy_toio(memptr
, p
, n
);
4293 spin_unlock_irqrestore(&brd_lock
, flags
);
4299 free_page((unsigned long) p
);
4304 /*****************************************************************************/
4307 * Return the board stats structure to user app.
4310 static int stli_getbrdstats(combrd_t __user
*bp
)
4315 if (copy_from_user(&stli_brdstats
, bp
, sizeof(combrd_t
)))
4317 if (stli_brdstats
.brd
>= STL_MAXBRDS
)
4319 brdp
= stli_brds
[stli_brdstats
.brd
];
4323 memset(&stli_brdstats
, 0, sizeof(combrd_t
));
4324 stli_brdstats
.brd
= brdp
->brdnr
;
4325 stli_brdstats
.type
= brdp
->brdtype
;
4326 stli_brdstats
.hwid
= 0;
4327 stli_brdstats
.state
= brdp
->state
;
4328 stli_brdstats
.ioaddr
= brdp
->iobase
;
4329 stli_brdstats
.memaddr
= brdp
->memaddr
;
4330 stli_brdstats
.nrpanels
= brdp
->nrpanels
;
4331 stli_brdstats
.nrports
= brdp
->nrports
;
4332 for (i
= 0; (i
< brdp
->nrpanels
); i
++) {
4333 stli_brdstats
.panels
[i
].panel
= i
;
4334 stli_brdstats
.panels
[i
].hwid
= brdp
->panelids
[i
];
4335 stli_brdstats
.panels
[i
].nrports
= brdp
->panels
[i
];
4338 if (copy_to_user(bp
, &stli_brdstats
, sizeof(combrd_t
)))
4343 /*****************************************************************************/
4346 * Resolve the referenced port number into a port struct pointer.
4349 static stliport_t
*stli_getport(int brdnr
, int panelnr
, int portnr
)
4354 if (brdnr
< 0 || brdnr
>= STL_MAXBRDS
)
4356 brdp
= stli_brds
[brdnr
];
4359 for (i
= 0; (i
< panelnr
); i
++)
4360 portnr
+= brdp
->panels
[i
];
4361 if ((portnr
< 0) || (portnr
>= brdp
->nrports
))
4363 return brdp
->ports
[portnr
];
4366 /*****************************************************************************/
4369 * Return the port stats structure to user app. A NULL port struct
4370 * pointer passed in means that we need to find out from the app
4371 * what port to get stats for (used through board control device).
4374 static int stli_portcmdstats(stliport_t
*portp
)
4376 unsigned long flags
;
4380 memset(&stli_comstats
, 0, sizeof(comstats_t
));
4384 brdp
= stli_brds
[portp
->brdnr
];
4388 if (brdp
->state
& BST_STARTED
) {
4389 if ((rc
= stli_cmdwait(brdp
, portp
, A_GETSTATS
,
4390 &stli_cdkstats
, sizeof(asystats_t
), 1)) < 0)
4393 memset(&stli_cdkstats
, 0, sizeof(asystats_t
));
4396 stli_comstats
.brd
= portp
->brdnr
;
4397 stli_comstats
.panel
= portp
->panelnr
;
4398 stli_comstats
.port
= portp
->portnr
;
4399 stli_comstats
.state
= portp
->state
;
4400 stli_comstats
.flags
= portp
->flags
;
4402 spin_lock_irqsave(&brd_lock
, flags
);
4403 if (portp
->tty
!= NULL
) {
4404 if (portp
->tty
->driver_data
== portp
) {
4405 stli_comstats
.ttystate
= portp
->tty
->flags
;
4406 stli_comstats
.rxbuffered
= -1;
4407 if (portp
->tty
->termios
!= NULL
) {
4408 stli_comstats
.cflags
= portp
->tty
->termios
->c_cflag
;
4409 stli_comstats
.iflags
= portp
->tty
->termios
->c_iflag
;
4410 stli_comstats
.oflags
= portp
->tty
->termios
->c_oflag
;
4411 stli_comstats
.lflags
= portp
->tty
->termios
->c_lflag
;
4415 spin_unlock_irqrestore(&brd_lock
, flags
);
4417 stli_comstats
.txtotal
= stli_cdkstats
.txchars
;
4418 stli_comstats
.rxtotal
= stli_cdkstats
.rxchars
+ stli_cdkstats
.ringover
;
4419 stli_comstats
.txbuffered
= stli_cdkstats
.txringq
;
4420 stli_comstats
.rxbuffered
+= stli_cdkstats
.rxringq
;
4421 stli_comstats
.rxoverrun
= stli_cdkstats
.overruns
;
4422 stli_comstats
.rxparity
= stli_cdkstats
.parity
;
4423 stli_comstats
.rxframing
= stli_cdkstats
.framing
;
4424 stli_comstats
.rxlost
= stli_cdkstats
.ringover
;
4425 stli_comstats
.rxbreaks
= stli_cdkstats
.rxbreaks
;
4426 stli_comstats
.txbreaks
= stli_cdkstats
.txbreaks
;
4427 stli_comstats
.txxon
= stli_cdkstats
.txstart
;
4428 stli_comstats
.txxoff
= stli_cdkstats
.txstop
;
4429 stli_comstats
.rxxon
= stli_cdkstats
.rxstart
;
4430 stli_comstats
.rxxoff
= stli_cdkstats
.rxstop
;
4431 stli_comstats
.rxrtsoff
= stli_cdkstats
.rtscnt
/ 2;
4432 stli_comstats
.rxrtson
= stli_cdkstats
.rtscnt
- stli_comstats
.rxrtsoff
;
4433 stli_comstats
.modem
= stli_cdkstats
.dcdcnt
;
4434 stli_comstats
.hwid
= stli_cdkstats
.hwid
;
4435 stli_comstats
.signals
= stli_mktiocm(stli_cdkstats
.signals
);
4440 /*****************************************************************************/
4443 * Return the port stats structure to user app. A NULL port struct
4444 * pointer passed in means that we need to find out from the app
4445 * what port to get stats for (used through board control device).
4448 static int stli_getportstats(stliport_t
*portp
, comstats_t __user
*cp
)
4454 if (copy_from_user(&stli_comstats
, cp
, sizeof(comstats_t
)))
4456 portp
= stli_getport(stli_comstats
.brd
, stli_comstats
.panel
,
4457 stli_comstats
.port
);
4462 brdp
= stli_brds
[portp
->brdnr
];
4466 if ((rc
= stli_portcmdstats(portp
)) < 0)
4469 return copy_to_user(cp
, &stli_comstats
, sizeof(comstats_t
)) ?
4473 /*****************************************************************************/
4476 * Clear the port stats structure. We also return it zeroed out...
4479 static int stli_clrportstats(stliport_t
*portp
, comstats_t __user
*cp
)
4485 if (copy_from_user(&stli_comstats
, cp
, sizeof(comstats_t
)))
4487 portp
= stli_getport(stli_comstats
.brd
, stli_comstats
.panel
,
4488 stli_comstats
.port
);
4493 brdp
= stli_brds
[portp
->brdnr
];
4497 if (brdp
->state
& BST_STARTED
) {
4498 if ((rc
= stli_cmdwait(brdp
, portp
, A_CLEARSTATS
, NULL
, 0, 0)) < 0)
4502 memset(&stli_comstats
, 0, sizeof(comstats_t
));
4503 stli_comstats
.brd
= portp
->brdnr
;
4504 stli_comstats
.panel
= portp
->panelnr
;
4505 stli_comstats
.port
= portp
->portnr
;
4507 if (copy_to_user(cp
, &stli_comstats
, sizeof(comstats_t
)))
4512 /*****************************************************************************/
4515 * Return the entire driver ports structure to a user app.
4518 static int stli_getportstruct(stliport_t __user
*arg
)
4522 if (copy_from_user(&stli_dummyport
, arg
, sizeof(stliport_t
)))
4524 portp
= stli_getport(stli_dummyport
.brdnr
, stli_dummyport
.panelnr
,
4525 stli_dummyport
.portnr
);
4528 if (copy_to_user(arg
, portp
, sizeof(stliport_t
)))
4533 /*****************************************************************************/
4536 * Return the entire driver board structure to a user app.
4539 static int stli_getbrdstruct(stlibrd_t __user
*arg
)
4543 if (copy_from_user(&stli_dummybrd
, arg
, sizeof(stlibrd_t
)))
4545 if ((stli_dummybrd
.brdnr
< 0) || (stli_dummybrd
.brdnr
>= STL_MAXBRDS
))
4547 brdp
= stli_brds
[stli_dummybrd
.brdnr
];
4550 if (copy_to_user(arg
, brdp
, sizeof(stlibrd_t
)))
4555 /*****************************************************************************/
4558 * The "staliomem" device is also required to do some special operations on
4559 * the board. We need to be able to send an interrupt to the board,
4560 * reset it, and start/stop it.
4563 static int stli_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
)
4566 int brdnr
, rc
, done
;
4567 void __user
*argp
= (void __user
*)arg
;
4570 * First up handle the board independent ioctls.
4576 case COM_GETPORTSTATS
:
4577 rc
= stli_getportstats(NULL
, argp
);
4580 case COM_CLRPORTSTATS
:
4581 rc
= stli_clrportstats(NULL
, argp
);
4584 case COM_GETBRDSTATS
:
4585 rc
= stli_getbrdstats(argp
);
4589 rc
= stli_getportstruct(argp
);
4593 rc
= stli_getbrdstruct(argp
);
4602 * Now handle the board specific ioctls. These all depend on the
4603 * minor number of the device they were called from.
4606 if (brdnr
>= STL_MAXBRDS
)
4608 brdp
= stli_brds
[brdnr
];
4611 if (brdp
->state
== 0)
4619 rc
= stli_startbrd(brdp
);
4622 brdp
->state
&= ~BST_STARTED
;
4625 brdp
->state
&= ~BST_STARTED
;
4627 if (stli_shared
== 0) {
4628 if (brdp
->reenable
!= NULL
)
4629 (* brdp
->reenable
)(brdp
);
4639 static const struct tty_operations stli_ops
= {
4641 .close
= stli_close
,
4642 .write
= stli_write
,
4643 .put_char
= stli_putchar
,
4644 .flush_chars
= stli_flushchars
,
4645 .write_room
= stli_writeroom
,
4646 .chars_in_buffer
= stli_charsinbuffer
,
4647 .ioctl
= stli_ioctl
,
4648 .set_termios
= stli_settermios
,
4649 .throttle
= stli_throttle
,
4650 .unthrottle
= stli_unthrottle
,
4652 .start
= stli_start
,
4653 .hangup
= stli_hangup
,
4654 .flush_buffer
= stli_flushbuffer
,
4655 .break_ctl
= stli_breakctl
,
4656 .wait_until_sent
= stli_waituntilsent
,
4657 .send_xchar
= stli_sendxchar
,
4658 .read_proc
= stli_readproc
,
4659 .tiocmget
= stli_tiocmget
,
4660 .tiocmset
= stli_tiocmset
,
4663 /*****************************************************************************/
4665 static int __init
stli_init(void)
4668 printk(KERN_INFO
"%s: version %s\n", stli_drvtitle
, stli_drvversion
);
4670 spin_lock_init(&stli_lock
);
4671 spin_lock_init(&brd_lock
);
4675 stli_serial
= alloc_tty_driver(STL_MAXBRDS
* STL_MAXPORTS
);
4680 * Allocate a temporary write buffer.
4682 stli_txcookbuf
= kmalloc(STLI_TXBUFSIZE
, GFP_KERNEL
);
4683 if (!stli_txcookbuf
)
4684 printk(KERN_ERR
"STALLION: failed to allocate memory "
4685 "(size=%d)\n", STLI_TXBUFSIZE
);
4688 * Set up a character driver for the shared memory region. We need this
4689 * to down load the slave code image. Also it is a useful debugging tool.
4691 if (register_chrdev(STL_SIOMEMMAJOR
, "staliomem", &stli_fsiomem
))
4692 printk(KERN_ERR
"STALLION: failed to register serial memory "
4695 istallion_class
= class_create(THIS_MODULE
, "staliomem");
4696 for (i
= 0; i
< 4; i
++)
4697 class_device_create(istallion_class
, NULL
,
4698 MKDEV(STL_SIOMEMMAJOR
, i
),
4699 NULL
, "staliomem%d", i
);
4702 * Set up the tty driver structure and register us as a driver.
4704 stli_serial
->owner
= THIS_MODULE
;
4705 stli_serial
->driver_name
= stli_drvname
;
4706 stli_serial
->name
= stli_serialname
;
4707 stli_serial
->major
= STL_SERIALMAJOR
;
4708 stli_serial
->minor_start
= 0;
4709 stli_serial
->type
= TTY_DRIVER_TYPE_SERIAL
;
4710 stli_serial
->subtype
= SERIAL_TYPE_NORMAL
;
4711 stli_serial
->init_termios
= stli_deftermios
;
4712 stli_serial
->flags
= TTY_DRIVER_REAL_RAW
;
4713 tty_set_operations(stli_serial
, &stli_ops
);
4715 if (tty_register_driver(stli_serial
)) {
4716 put_tty_driver(stli_serial
);
4717 printk(KERN_ERR
"STALLION: failed to register serial driver\n");
4723 /*****************************************************************************/