2 /* sx.c -- driver for the Specialix SX series cards.
4 * This driver will also support the older SI, and XIO cards.
7 * (C) 1998 - 2000 R.E.Wolff@BitWizard.nl
9 * Simon Allen (simonallen@cix.compulink.co.uk) wrote a previous
10 * version of this driver. Some fragments may have been copied. (none
13 * Specialix pays for the development and support of this driver.
14 * Please DO contact support@specialix.co.uk if you require
15 * support. But please read the documentation (sx.txt) first.
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License as
21 * published by the Free Software Foundation; either version 2 of
22 * the License, or (at your option) any later version.
24 * This program is distributed in the hope that it will be
25 * useful, but WITHOUT ANY WARRANTY; without even the implied
26 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
27 * PURPOSE. See the GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public
30 * License along with this program; if not, write to the Free
31 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
36 * Revision 1.1.1.1 2005/04/11 02:50:19 jack
39 * Revision 1.1.1.1 2005/01/10 13:16:18 jack
42 * Revision 1.33 2000/03/09 10:00:00 pvdl,wolff
43 * - Fixed module and port counting
44 * - Fixed signal handling
47 * Revision 1.32 2000/03/07 09:00:00 wolff,pvdl
48 * - Fixed some sx_dprintk typos
49 * - added detection for an invalid board/module configuration
51 * Revision 1.31 2000/03/06 12:00:00 wolff,pvdl
52 * - Added support for EISA
54 * Revision 1.30 2000/01/21 17:43:06 wolff
55 * - Added support for SX+
57 * Revision 1.26 1999/08/05 15:22:14 wolff
59 * - Reformatted to Linus' liking.
61 * Revision 1.25 1999/07/30 14:24:08 wolff
62 * Had accidentally left "gs_debug" set to "-1" instead of "off" (=0).
64 * Revision 1.24 1999/07/28 09:41:52 wolff
65 * - I noticed the remark about use-count straying in sx.txt. I checked
66 * sx_open, and found a few places where that could happen. I hope it's
69 * Revision 1.23 1999/07/28 08:56:06 wolff
70 * - Fixed crash when sx_firmware run twice.
71 * - Added sx_slowpoll as a module parameter (I guess nobody really wanted
72 * to change it from the default... )
73 * - Fixed a stupid editing problem I introduced in 1.22.
74 * - Fixed dropping characters on a termios change.
76 * Revision 1.22 1999/07/26 21:01:43 wolff
77 * Russell Brown noticed that I had overlooked 4 out of six modem control
78 * signals in sx_getsignals. Ooops.
80 * Revision 1.21 1999/07/23 09:11:33 wolff
81 * I forgot to free dynamically allocated memory when the driver is unloaded.
83 * Revision 1.20 1999/07/20 06:25:26 wolff
84 * The "closing wait" wasn't honoured. Thanks to James Griffiths for
87 * Revision 1.19 1999/07/11 08:59:59 wolff
88 * Fixed an oops in close, when an open was pending. Changed the memtest
89 * a bit. Should also test the board in word-mode, however my card fails the
90 * memtest then. I still have to figure out what is wrong...
92 * Revision 1.18 1999/06/10 09:38:42 wolff
93 * Changed the format of the firmware revision from %04x to %x.%02x .
95 * Revision 1.17 1999/06/04 09:44:35 wolff
96 * fixed problem: reference to pci stuff when config_pci was off...
97 * Thanks to Jorge Novo for noticing this.
99 * Revision 1.16 1999/06/02 08:30:15 wolff
100 * added/removed the workaround for the DCD bug in the Firmware.
101 * A bit more debugging code to locate that...
103 * Revision 1.15 1999/06/01 11:35:30 wolff
104 * when DCD is left low (floating?), on TA's the firmware first tells us
105 * that DCD is high, but after a short while suddenly comes to the
106 * conclusion that it is low. All this would be fine, if it weren't that
107 * Unix requires us to send a "hangup" signal in that case. This usually
108 * all happens BEFORE the program has had a chance to ioctl the device
111 * Revision 1.14 1999/05/25 11:18:59 wolff
113 * Added checks for return code of sx_sendcommand.
114 * Don't issue "reconfig" if port isn't open yet. (bit us on TA modules...)
116 * Revision 1.13 1999/04/29 15:18:01 wolff
117 * Fixed an "oops" that showed on SuSE 6.0 systems.
118 * Activate DTR again after stty 0.
120 * Revision 1.12 1999/04/29 07:49:52 wolff
121 * Improved "stty 0" handling a bit. (used to change baud to 9600 assuming
122 * the connection would be dropped anyway. That is not always the case,
123 * and confuses people).
124 * Told the card to always monitor the modem signals.
125 * Added support for dynamic gs_debug adjustments.
126 * Now tells the rest of the system the number of ports.
128 * Revision 1.11 1999/04/24 11:11:30 wolff
129 * Fixed two stupid typos in the memory test.
131 * Revision 1.10 1999/04/24 10:53:39 wolff
132 * Added some of Christian's suggestions.
133 * Fixed an HW_COOK_IN bug (ISIG was not in I_OTHER. We used to trust the
134 * card to send the signal to the process.....)
136 * Revision 1.9 1999/04/23 07:26:38 wolff
137 * Included Christian Lademann's 2.0 compile-warning fixes and interrupt
138 * assignment redesign.
139 * Cleanup of some other stuff.
141 * Revision 1.8 1999/04/16 13:05:30 wolff
142 * fixed a DCD change unnoticed bug.
144 * Revision 1.7 1999/04/14 22:19:51 wolff
145 * Fixed typo that showed up in 2.0.x builds (get_user instead of Get_user!)
147 * Revision 1.6 1999/04/13 18:40:20 wolff
148 * changed misc-minor to 161, as assigned by HPA.
150 * Revision 1.5 1999/04/13 15:12:25 wolff
151 * Fixed use-count leak when "hangup" occurred.
152 * Added workaround for a stupid-PCIBIOS bug.
155 * Revision 1.4 1999/04/01 22:47:40 wolff
156 * Fixed < 1M linux-2.0 problem.
157 * (vremap isn't compatible with ioremap in that case)
159 * Revision 1.3 1999/03/31 13:45:45 wolff
160 * Firmware loading is now done through a separate IOCTL.
162 * Revision 1.2 1999/03/28 12:22:29 wolff
165 * Revision 1.1 1999/03/28 12:10:34 wolff
166 * Readying for release on 2.0.x (sorry David, 1.01 becomes 1.1 for RCS).
168 * Revision 0.12 1999/03/28 09:20:10 wolff
169 * Fixed problem in 0.11, continueing cleanup.
171 * Revision 0.11 1999/03/28 08:46:44 wolff
174 * Revision 0.10 1999/03/28 08:09:43 wolff
175 * Fixed loosing characters on close.
177 * Revision 0.9 1999/03/21 22:52:01 wolff
178 * Ported back to 2.2.... (minor things)
180 * Revision 0.8 1999/03/21 22:40:33 wolff
183 * Revision 0.7 1999/03/21 19:06:34 wolff
184 * Fixed hangup processing.
186 * Revision 0.6 1999/02/05 08:45:14 wolff
187 * fixed real_raw problems. Inclusion into kernel imminent.
189 * Revision 0.5 1998/12/21 23:51:06 wolff
190 * Snatched a nasty bug: sx_transmit_chars was getting re-entered, and it
191 * shouldn't have. THATs why I want to have transmit interrupts even when
192 * the buffer is empty.
194 * Revision 0.4 1998/12/17 09:34:46 wolff
195 * PPP works. ioctl works. Basically works!
197 * Revision 0.3 1998/12/15 13:05:18 wolff
198 * It works! Wow! Gotta start implementing IOCTL and stuff....
200 * Revision 0.2 1998/12/01 08:33:53 wolff
201 * moved over to 2.1.130
203 * Revision 0.1 1998/11/03 21:23:51 wolff
204 * Initial revision. Detects SX card.
209 #define RCS_ID "$Id: sx.c,v 1.1.1.1 2005/04/11 02:50:19 jack Exp $"
210 #define RCS_REV "$Revision: 1.1.1.1 $"
213 #include <linux/module.h>
214 #include <linux/config.h>
215 #include <linux/kdev_t.h>
217 #include <linux/kernel.h>
218 #include <linux/sched.h>
219 #include <linux/ioport.h>
220 #include <linux/interrupt.h>
221 #include <linux/errno.h>
222 #include <linux/tty.h>
223 #include <linux/tty_flip.h>
224 #include <linux/mm.h>
225 #include <linux/serial.h>
226 #include <linux/fcntl.h>
227 #include <linux/major.h>
228 #include <linux/delay.h>
229 #include <linux/tqueue.h>
230 #include <linux/version.h>
231 #include <linux/pci.h>
232 #include <linux/slab.h>
233 #include <linux/init.h>
234 #include <linux/miscdevice.h>
236 /* The 3.0.0 version of sxboards/sxwindow.h uses BYTE and WORD.... */
240 /* .... but the 3.0.4 version uses _u8 and _u16. */
244 #include "sxboards.h"
245 #include "sxwindow.h"
247 #include <linux/compatmac.h>
248 #include <linux/generic_serial.h>
252 /* I don't think that this driver can handle more than 256 ports on
253 one machine. You'll have to increase the number of boards in sx.h
254 if you want more than 4 boards. */
257 /* Why the hell am I defining these here? */
258 #define SX_TYPE_NORMAL 1
259 #define SX_TYPE_CALLOUT 2
262 #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
263 #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
266 static struct pci_device_id sx_pci_tbl[] = {
267 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, PCI_ANY_ID, PCI_ANY_ID },
270 MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
272 /* Configurable options:
273 (Don't be too sure that it'll work if you toggle them) */
275 /* Am I paranoid or not ? ;-) */
276 #undef SX_PARANOIA_CHECK
279 /* 20 -> 2000 per second. The card should rate-limit interrupts at 100
280 Hz, but it is user configurable. I don't recommend going above 1000
281 Hz. The interrupt ratelimit might trigger if the interrupt is
282 shared with a very active other device. */
283 #define IRQ_RATE_LIMIT 20
285 /* Sharing interrupts is possible now. If the other device wants more
286 than 2000 interrupts per second, we'd gracefully decline further
287 interrupts. That's not what we want. On the other hand, if the
288 other device interrupts 2000 times a second, don't use the SX
289 interrupt. Use polling. */
290 #undef IRQ_RATE_LIMIT
294 /* Not implemented */
296 * The following defines are mostly for testing purposes. But if you need
297 * some nice reporting in your syslog, you can define them also.
299 #define SX_REPORT_FIFO
300 #define SX_REPORT_OVERRUN
304 /* Function prototypes */
305 static void sx_disable_tx_interrupts (void * ptr);
306 static void sx_enable_tx_interrupts (void * ptr);
307 static void sx_disable_rx_interrupts (void * ptr);
308 static void sx_enable_rx_interrupts (void * ptr);
309 static int sx_get_CD (void * ptr);
310 static void sx_shutdown_port (void * ptr);
311 static int sx_set_real_termios (void *ptr);
312 static void sx_hungup (void *ptr);
313 static void sx_close (void *ptr);
314 static int sx_chars_in_buffer (void * ptr);
315 static int sx_init_board (struct sx_board *board);
316 static int sx_init_portstructs (int nboards, int nports);
317 static int sx_fw_ioctl (struct inode *inode, struct file *filp,
318 unsigned int cmd, unsigned long arg);
319 static int sx_init_drivers(void);
322 static struct tty_driver sx_driver, sx_callout_driver;
324 static struct tty_struct * sx_table[SX_NPORTS];
325 static struct termios ** sx_termios;
326 static struct termios ** sx_termios_locked;
328 static struct sx_board boards[SX_NBOARDS];
329 static struct sx_port *sx_ports;
330 static int sx_refcount;
331 static int sx_initialized;
332 static int sx_nports;
336 /* You can have the driver poll your card.
337 - Set sx_poll to 1 to poll every timer tick (10ms on Intel).
338 This is used when the card cannot use an interrupt for some reason.
340 - set sx_slowpoll to 100 to do an extra poll once a second (on Intel). If
341 the driver misses an interrupt (report this if it DOES happen to you!)
342 everything will continue to work....
344 static int sx_poll = 1;
345 static int sx_slowpoll;
347 /* The card limits the number of interrupts per second.
348 At 115k2 "100" should be sufficient.
349 If you're using higher baudrates, you can increase this...
352 static int sx_maxints = 100;
354 /* These are the only open spaces in my computer. Yours may have more
356 duh: Card at 0xa0000 is possible on HP Netserver?? -- pvdl
358 static int sx_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000,
359 0xc8000, 0xd8000, 0xe8000};
360 static int si_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000,
361 0xc8000, 0xd8000, 0xe8000, 0xa0000};
362 static int si1_probe_addrs[]= { 0xd0000};
364 #define NR_SX_ADDRS (sizeof(sx_probe_addrs)/sizeof (int))
365 #define NR_SI_ADDRS (sizeof(si_probe_addrs)/sizeof (int))
366 #define NR_SI1_ADDRS (sizeof(si1_probe_addrs)/sizeof (int))
369 /* Set the mask to all-ones. This alas, only supports 32 interrupts.
370 Some architectures may need more. */
371 static int sx_irqmask = -1;
373 MODULE_PARM(sx_probe_addrs, "i");
374 MODULE_PARM(si_probe_addrs, "i");
375 MODULE_PARM(sx_poll, "i");
376 MODULE_PARM(sx_slowpoll, "i");
377 MODULE_PARM(sx_maxints, "i");
378 MODULE_PARM(sx_debug, "i");
379 MODULE_PARM(sx_irqmask, "i");
381 MODULE_LICENSE("GPL");
383 static struct real_driver sx_real_driver = {
384 sx_disable_tx_interrupts,
385 sx_enable_tx_interrupts,
386 sx_disable_rx_interrupts,
387 sx_enable_rx_interrupts,
398 This driver can spew a whole lot of debugging output at you. If you
399 need maximum performance, you should disable the DEBUG define. To
400 aid in debugging in the field, I'm leaving the compile-time debug
401 features enabled, and disable them "runtime". That allows me to
402 instruct people with problems to enable debugging without requiring
409 #define sx_dprintk(f, str...) if (sx_debug & f) printk (str)
411 #define sx_dprintk(f, str...) /* nothing */
416 #define func_enter() sx_dprintk (SX_DEBUG_FLOW, "sx: enter %s\b",__FUNCTION__)
417 #define func_exit() sx_dprintk (SX_DEBUG_FLOW, "sx: exit %s\n", __FUNCTION__)
419 #define func_enter2() sx_dprintk (SX_DEBUG_FLOW, "sx: enter %s (port %d)\n", \
420 __FUNCTION__, port->line)
426 * Firmware loader driver specific routines
430 static struct file_operations sx_fw_fops = {
435 static struct miscdevice sx_fw_device = {
436 SXCTL_MISC_MINOR, "sxctl", &sx_fw_fops
443 #ifdef SX_PARANOIA_CHECK
445 /* This doesn't work. Who's paranoid around here? Not me! */
447 static inline int sx_paranoia_check(struct sx_port const * port,
448 kdev_t device, const char *routine)
451 static const char *badmagic =
452 KERN_ERR "sx: Warning: bad sx port magic number for device %s in %s\n";
453 static const char *badinfo =
454 KERN_ERR "sx: Warning: null sx port for device %s in %s\n";
457 printk(badinfo, kdevname(device), routine);
460 if (port->magic != SX_MAGIC) {
461 printk(badmagic, kdevname(device), routine);
468 #define sx_paranoia_check(a,b,c) 0
471 /* The timeouts. First try 30 times as fast as possible. Then give
472 the card some time to breathe between accesses. (Otherwise the
473 processor on the card might not be able to access its OWN bus... */
476 #define TIMEOUT_2 1000000
480 static void my_hd (unsigned char *addr, int len)
484 for (i=0;i<len;i+=16) {
485 printk ("%p ", addr+i);
487 printk ("%02x %s", addr[j+i], (j==7)?" ":"");
491 printk ("%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
500 /* This needs redoing for Alpha -- REW -- Done. */
502 static inline void write_sx_byte (struct sx_board *board, int offset, u8 byte)
504 writeb (byte, board->base+offset);
507 static inline u8 read_sx_byte (struct sx_board *board, int offset)
509 return readb (board->base+offset);
513 static inline void write_sx_word (struct sx_board *board, int offset, u16 word)
515 writew (word, board->base+offset);
518 static inline u16 read_sx_word (struct sx_board *board, int offset)
520 return readw (board->base + offset);
524 static int sx_busy_wait_eq (struct sx_board *board,
525 int offset, int mask, int correctval)
531 for (i=0; i < TIMEOUT_1 > 0;i++)
532 if ((read_sx_byte (board, offset) & mask) == correctval) {
537 for (i=0; i < TIMEOUT_2 > 0;i++) {
538 if ((read_sx_byte (board, offset) & mask) == correctval) {
550 static int sx_busy_wait_neq (struct sx_board *board,
551 int offset, int mask, int badval)
557 for (i=0; i < TIMEOUT_1 > 0;i++)
558 if ((read_sx_byte (board, offset) & mask) != badval) {
563 for (i=0; i < TIMEOUT_2 > 0;i++) {
564 if ((read_sx_byte (board, offset) & mask) != badval) {
577 /* 5.6.4 of 6210028 r2.3 */
578 static int sx_reset (struct sx_board *board)
582 if (IS_SX_BOARD (board)) {
584 write_sx_byte (board, SX_CONFIG, 0);
585 write_sx_byte (board, SX_RESET, 1); /* Value doesn't matter */
587 if (!sx_busy_wait_eq (board, SX_RESET_STATUS, 1, 0)) {
588 printk (KERN_INFO "sx: Card doesn't respond to reset....\n");
591 } else if (IS_EISA_BOARD(board)) {
592 outb(board->irq<<4, board->eisa_base+0xc02);
593 } else if (IS_SI1_BOARD(board)) {
594 write_sx_byte (board, SI1_ISA_RESET, 0); // value does not matter
596 /* Gory details of the SI/ISA board */
597 write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_SET);
598 write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_CLEAR);
599 write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_CLEAR);
600 write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_CLEAR);
601 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR);
602 write_sx_byte (board, SI2_ISA_IRQSET, SI2_ISA_IRQSET_CLEAR);
610 /* This doesn't work on machines where "NULL" isn't 0 */
611 /* If you have one of those, someone will need to write
612 the equivalent of this, which will amount to about 3 lines. I don't
613 want to complicate this right now. -- REW
614 (See, I do write comments every now and then :-) */
615 #define OFFSETOF(strct, elem) ((long)&(((struct strct *)NULL)->elem))
618 #define CHAN_OFFSET(port,elem) (port->ch_base + OFFSETOF (_SXCHANNEL, elem))
619 #define MODU_OFFSET(board,addr,elem) (addr + OFFSETOF (_SXMODULE, elem))
620 #define BRD_OFFSET(board,elem) (OFFSETOF (_SXCARD, elem))
623 #define sx_write_channel_byte(port, elem, val) \
624 write_sx_byte (port->board, CHAN_OFFSET (port, elem), val)
626 #define sx_read_channel_byte(port, elem) \
627 read_sx_byte (port->board, CHAN_OFFSET (port, elem))
629 #define sx_write_channel_word(port, elem, val) \
630 write_sx_word (port->board, CHAN_OFFSET (port, elem), val)
632 #define sx_read_channel_word(port, elem) \
633 read_sx_word (port->board, CHAN_OFFSET (port, elem))
636 #define sx_write_module_byte(board, addr, elem, val) \
637 write_sx_byte (board, MODU_OFFSET (board, addr, elem), val)
639 #define sx_read_module_byte(board, addr, elem) \
640 read_sx_byte (board, MODU_OFFSET (board, addr, elem))
642 #define sx_write_module_word(board, addr, elem, val) \
643 write_sx_word (board, MODU_OFFSET (board, addr, elem), val)
645 #define sx_read_module_word(board, addr, elem) \
646 read_sx_word (board, MODU_OFFSET (board, addr, elem))
649 #define sx_write_board_byte(board, elem, val) \
650 write_sx_byte (board, BRD_OFFSET (board, elem), val)
652 #define sx_read_board_byte(board, elem) \
653 read_sx_byte (board, BRD_OFFSET (board, elem))
655 #define sx_write_board_word(board, elem, val) \
656 write_sx_word (board, BRD_OFFSET (board, elem), val)
658 #define sx_read_board_word(board, elem) \
659 read_sx_word (board, BRD_OFFSET (board, elem))
662 static int sx_start_board (struct sx_board *board)
664 if (IS_SX_BOARD (board)) {
665 write_sx_byte (board, SX_CONFIG, SX_CONF_BUSEN);
666 } else if (IS_EISA_BOARD(board)) {
667 write_sx_byte(board, SI2_EISA_OFF, SI2_EISA_VAL);
668 outb((board->irq<<4)|4, board->eisa_base+0xc02);
669 } else if (IS_SI1_BOARD(board)) {
670 write_sx_byte (board, SI1_ISA_RESET_CLEAR, 0);
671 write_sx_byte (board, SI1_ISA_INTCL, 0);
673 /* Don't bug me about the clear_set.
674 I haven't the foggiest idea what it's about -- REW */
675 write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_CLEAR);
676 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
681 #define SX_IRQ_REG_VAL(board) \
682 ((board->flags & SX_ISA_BOARD)?(board->irq << 4):0)
684 /* Note. The SX register is write-only. Therefore, we have to enable the
685 bus too. This is a no-op, if you don't mess with this driver... */
686 static int sx_start_interrupts (struct sx_board *board)
689 /* Don't call this with board->irq == 0 */
691 if (IS_SX_BOARD(board)) {
692 write_sx_byte (board, SX_CONFIG, SX_IRQ_REG_VAL (board) |
695 } else if (IS_EISA_BOARD(board)) {
696 inb(board->eisa_base+0xc03);
697 } else if (IS_SI1_BOARD(board)) {
698 write_sx_byte (board, SI1_ISA_INTCL,0);
699 write_sx_byte (board, SI1_ISA_INTCL_CLEAR,0);
701 switch (board->irq) {
702 case 11:write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_SET);break;
703 case 12:write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_SET);break;
704 case 15:write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_SET);break;
705 default:printk (KERN_INFO "sx: SI/XIO card doesn't support interrupt %d.\n",
709 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
716 static int sx_send_command (struct sx_port *port,
717 int command, int mask, int newstat)
720 write_sx_byte (port->board, CHAN_OFFSET (port, hi_hstat), command);
722 return sx_busy_wait_eq (port->board, CHAN_OFFSET (port, hi_hstat), mask, newstat);
726 static char *mod_type_s (int module_type)
728 switch (module_type) {
729 case TA4: return "TA4";
730 case TA8: return "TA8";
731 case TA4_ASIC: return "TA4_ASIC";
732 case TA8_ASIC: return "TA8_ASIC";
733 case MTA_CD1400:return "MTA_CD1400";
734 case SXDC: return "SXDC";
735 default:return "Unknown/invalid";
740 static char *pan_type_s (int pan_type)
743 case MOD_RS232DB25: return "MOD_RS232DB25";
744 case MOD_RS232RJ45: return "MOD_RS232RJ45";
745 case MOD_RS422DB25: return "MOD_RS422DB25";
746 case MOD_PARALLEL: return "MOD_PARALLEL";
747 case MOD_2_RS232DB25: return "MOD_2_RS232DB25";
748 case MOD_2_RS232RJ45: return "MOD_2_RS232RJ45";
749 case MOD_2_RS422DB25: return "MOD_2_RS422DB25";
750 case MOD_RS232DB25MALE: return "MOD_RS232DB25MALE";
751 case MOD_2_PARALLEL: return "MOD_2_PARALLEL";
752 case MOD_BLANK: return "empty";
753 default:return "invalid";
758 static int mod_compat_type (int module_type)
760 return module_type >> 4;
763 static void sx_reconfigure_port(struct sx_port *port)
765 if (sx_read_channel_byte (port, hi_hstat) == HS_IDLE_OPEN) {
766 if (sx_send_command (port, HS_CONFIG, -1, HS_IDLE_OPEN) != 1) {
767 printk (KERN_WARNING "sx: Sent reconfigure command, but card didn't react.\n");
770 sx_dprintk (SX_DEBUG_TERMIOS,
771 "sx: Not sending reconfigure: port isn't open (%02x).\n",
772 sx_read_channel_byte (port, hi_hstat));
776 static void sx_setsignals (struct sx_port *port, int dtr, int rts)
781 t = sx_read_channel_byte (port, hi_op);
782 if (dtr >= 0) t = dtr? (t | OP_DTR): (t & ~OP_DTR);
783 if (rts >= 0) t = rts? (t | OP_RTS): (t & ~OP_RTS);
784 sx_write_channel_byte (port, hi_op, t);
785 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "setsignals: %d/%d\n", dtr, rts);
792 static int sx_getsignals (struct sx_port *port)
796 o_stat = sx_read_channel_byte (port, hi_op);
797 i_stat = sx_read_channel_byte (port, hi_ip);
799 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) %02x/%02x\n",
800 (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0,
801 port->c_dcd, sx_get_CD (port),
802 sx_read_channel_byte (port, hi_ip),
803 sx_read_channel_byte (port, hi_state));
805 return (((o_stat & OP_DTR)?TIOCM_DTR:0) |
806 ((o_stat & OP_RTS)?TIOCM_RTS:0) |
807 ((i_stat & IP_CTS)?TIOCM_CTS:0) |
808 ((i_stat & IP_DCD)?TIOCM_CAR:0) |
809 ((i_stat & IP_DSR)?TIOCM_DSR:0) |
810 ((i_stat & IP_RI)?TIOCM_RNG:0)
815 static void sx_set_baud (struct sx_port *port)
819 if (port->board->ta_type == MOD_SXDC) {
820 switch (port->gs.baud) {
821 /* Save some typing work... */
822 #define e(x) case x:t= BAUD_ ## x ; break
823 e(50);e(75);e(110);e(150);e(200);e(300);e(600);
824 e(1200);e(1800);e(2000);e(2400);e(4800);e(7200);
825 e(9600);e(14400);e(19200);e(28800);e(38400);
826 e(56000);e(57600);e(64000);e(76800);e(115200);
827 e(128000);e(150000);e(230400);e(256000);e(460800);
829 case 134 :t = BAUD_134_5; break;
833 /* Can I return "invalid"? */
835 printk (KERN_INFO "sx: unsupported baud rate: %d.\n", port->gs.baud);
840 /* The baud rate is not set to 0, so we're enabeling DTR... -- REW */
841 sx_setsignals (port, 1, -1);
842 /* XXX This is not TA & MTA compatible */
843 sx_write_channel_byte (port, hi_csr, 0xff);
845 sx_write_channel_byte (port, hi_txbaud, t);
846 sx_write_channel_byte (port, hi_rxbaud, t);
848 sx_setsignals (port, 0, -1);
851 switch (port->gs.baud) {
852 #define e(x) case x:t= CSR_ ## x ; break
853 e(75);e(150);e(300);e(600);e(1200);e(2400);e(4800);
855 e(19200);e(57600);e(38400);
856 /* TA supports 110, but not 115200, MTA supports 115200, but not 110 */
858 if (port->board->ta_type == MOD_TA) {
863 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
867 if (port->board->ta_type == MOD_TA) {
869 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
879 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
884 sx_setsignals (port, 1, -1);
885 sx_write_channel_byte (port, hi_csr, t * 0x11);
887 sx_setsignals (port, 0, -1);
893 /* Simon Allen's version of this routine was 225 lines long. 85 is a lot
896 static int sx_set_real_termios (void *ptr)
898 struct sx_port *port = ptr;
905 /* What is this doing here? -- REW
906 Ha! figured it out. It is to allow you to get DTR active again
907 if you've dropped it with stty 0. Moved to set_baud, where it
908 belongs (next to the drop dtr if baud == 0) -- REW */
909 /* sx_setsignals (port, 1, -1); */
913 #define CFLAG port->gs.tty->termios->c_cflag
914 sx_write_channel_byte (port, hi_mr1,
915 (C_PARENB (port->gs.tty)? MR1_WITH:MR1_NONE) |
916 (C_PARODD (port->gs.tty)? MR1_ODD:MR1_EVEN) |
917 (C_CRTSCTS(port->gs.tty)? MR1_RTS_RXFLOW:0) |
918 (((CFLAG & CSIZE)==CS8) ? MR1_8_BITS:0) |
919 (((CFLAG & CSIZE)==CS7) ? MR1_7_BITS:0) |
920 (((CFLAG & CSIZE)==CS6) ? MR1_6_BITS:0) |
921 (((CFLAG & CSIZE)==CS5) ? MR1_5_BITS:0) );
923 sx_write_channel_byte (port, hi_mr2,
924 (C_CRTSCTS(port->gs.tty)?MR2_CTS_TXFLOW:0) |
925 (C_CSTOPB (port->gs.tty)?MR2_2_STOP:MR2_1_STOP));
927 switch (CFLAG & CSIZE) {
928 case CS8:sx_write_channel_byte (port, hi_mask, 0xff);break;
929 case CS7:sx_write_channel_byte (port, hi_mask, 0x7f);break;
930 case CS6:sx_write_channel_byte (port, hi_mask, 0x3f);break;
931 case CS5:sx_write_channel_byte (port, hi_mask, 0x1f);break;
933 printk (KERN_INFO "sx: Invalid wordsize: %d\n", CFLAG & CSIZE);
937 sx_write_channel_byte (port, hi_prtcl,
938 (I_IXON (port->gs.tty)?SP_TXEN:0) |
939 (I_IXOFF (port->gs.tty)?SP_RXEN:0) |
940 (I_IXANY (port->gs.tty)?SP_TANY:0) |
943 sx_write_channel_byte (port, hi_break,
944 (I_IGNBRK(port->gs.tty)?BR_IGN:0 |
945 I_BRKINT(port->gs.tty)?BR_INT:0));
947 sx_write_channel_byte (port, hi_txon, START_CHAR (port->gs.tty));
948 sx_write_channel_byte (port, hi_rxon, START_CHAR (port->gs.tty));
949 sx_write_channel_byte (port, hi_txoff, STOP_CHAR (port->gs.tty));
950 sx_write_channel_byte (port, hi_rxoff, STOP_CHAR (port->gs.tty));
952 sx_reconfigure_port(port);
954 /* Tell line discipline whether we will do input cooking */
955 if(I_OTHER(port->gs.tty)) {
956 clear_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
958 set_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
960 sx_dprintk (SX_DEBUG_TERMIOS, "iflags: %x(%d) ",
961 port->gs.tty->termios->c_iflag,
962 I_OTHER(port->gs.tty));
965 /* Tell line discipline whether we will do output cooking.
966 * If OPOST is set and no other output flags are set then we can do output
967 * processing. Even if only *one* other flag in the O_OTHER group is set
968 * we do cooking in software.
970 if(O_OPOST(port->gs.tty) && !O_OTHER(port->gs.tty)) {
971 set_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
973 clear_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
975 sx_dprintk (SX_DEBUG_TERMIOS, "oflags: %x(%d)\n",
976 port->gs.tty->termios->c_oflag,
977 O_OTHER(port->gs.tty));
978 /* port->c_dcd = sx_get_CD (port); */
985 /* ********************************************************************** *
986 * the interrupt related routines *
987 * ********************************************************************** */
990 Other drivers use the macro "MIN" to calculate how much to copy.
991 This has the disadvantage that it will evaluate parts twice. That's
992 expensive when it's IO (and the compiler cannot optimize those away!).
993 Moreover, I'm not sure that you're race-free.
995 I assign a value, and then only allow the value to decrease. This
996 is always safe. This makes the code a few lines longer, and you
997 know I'm dead against that, but I think it is required in this
1001 static void sx_transmit_chars (struct sx_port *port)
1008 sx_dprintk (SX_DEBUG_TRANSMIT, "Port %p: transmit %d chars\n",
1009 port, port->gs.xmit_cnt);
1011 if (test_and_set_bit (SX_PORT_TRANSMIT_LOCK, &port->locks)) {
1016 c = port->gs.xmit_cnt;
1018 sx_dprintk (SX_DEBUG_TRANSMIT, "Copying %d ", c);
1019 tx_ip = sx_read_channel_byte (port, hi_txipos);
1021 /* Took me 5 minutes to deduce this formula.
1022 Luckily it is literally in the manual in section 6.5.4.3.5 */
1023 txroom = (sx_read_channel_byte (port, hi_txopos) - tx_ip - 1) & 0xff;
1025 /* Don't copy more bytes than there is room for in the buffer */
1028 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, txroom );
1030 /* Don't copy past the end of the hardware transmit buffer */
1031 if (c > 0x100 - tx_ip)
1034 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, 0x100-tx_ip );
1036 /* Don't copy pas the end of the source buffer */
1037 if (c > SERIAL_XMIT_SIZE - port->gs.xmit_tail)
1038 c = SERIAL_XMIT_SIZE - port->gs.xmit_tail;
1040 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%ld) \n",
1041 c, SERIAL_XMIT_SIZE- port->gs.xmit_tail);
1043 /* If for one reason or another, we can't copy more data, we're done! */
1047 memcpy_toio (port->board->base + CHAN_OFFSET(port,hi_txbuf) + tx_ip,
1048 port->gs.xmit_buf + port->gs.xmit_tail, c);
1050 /* Update the pointer in the card */
1051 sx_write_channel_byte (port, hi_txipos, (tx_ip+c) & 0xff);
1053 /* Update the kernel buffer end */
1054 port->gs.xmit_tail = (port->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE-1);
1056 /* This one last. (this is essential)
1057 It would allow others to start putting more data into the buffer! */
1058 port->gs.xmit_cnt -= c;
1061 if (port->gs.xmit_cnt == 0) {
1062 sx_disable_tx_interrupts (port);
1065 if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.tty) {
1066 if ((port->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1067 port->gs.tty->ldisc.write_wakeup)
1068 (port->gs.tty->ldisc.write_wakeup)(port->gs.tty);
1069 sx_dprintk (SX_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n",
1070 port->gs.wakeup_chars);
1071 wake_up_interruptible(&port->gs.tty->write_wait);
1074 clear_bit (SX_PORT_TRANSMIT_LOCK, &port->locks);
1079 /* Note the symmetry between receiving chars and transmitting them!
1080 Note: The kernel should have implemented both a receive buffer and
1081 a transmit buffer. */
1083 /* Inlined: Called only once. Remove the inline when you add another call */
1084 static inline void sx_receive_chars (struct sx_port *port)
1088 struct tty_struct *tty;
1094 rx_op = sx_read_channel_byte (port, hi_rxopos);
1095 c = (sx_read_channel_byte (port, hi_rxipos) - rx_op) & 0xff;
1097 sx_dprintk (SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c);
1099 /* Don't copy more bytes than there is room for in the buffer */
1100 if (tty->flip.count + c > TTY_FLIPBUF_SIZE)
1101 c = TTY_FLIPBUF_SIZE - tty->flip.count;
1103 sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
1105 /* Don't copy past the end of the hardware receive buffer */
1106 if (rx_op + c > 0x100) c = 0x100 - rx_op;
1108 sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
1110 /* If for one reason or another, we can't copy more data, we're done! */
1113 sx_dprintk (SX_DEBUG_RECEIVE , "Copying over %d chars. First is %d at %lx\n", c,
1114 read_sx_byte (port->board, CHAN_OFFSET(port,hi_rxbuf) + rx_op),
1115 CHAN_OFFSET(port, hi_rxbuf));
1116 memcpy_fromio (tty->flip.char_buf_ptr,
1117 port->board->base + CHAN_OFFSET(port,hi_rxbuf) + rx_op, c);
1118 memset(tty->flip.flag_buf_ptr, TTY_NORMAL, c);
1120 /* Update the kernel buffer end */
1121 tty->flip.count += c;
1122 tty->flip.char_buf_ptr += c;
1123 tty->flip.flag_buf_ptr += c;
1125 /* This one last. ( Not essential.)
1126 It allows the card to start putting more data into the buffer!
1127 Update the pointer in the card */
1128 sx_write_channel_byte (port, hi_rxopos, (rx_op + c) & 0xff);
1135 do_gettimeofday (&tv);
1136 sx_dprintk (SX_DEBUG_RECEIVE,
1137 "pushing flipq port %d (%3d chars): %d.%06d (%d/%d)\n",
1139 (int) (tv.tv_sec % 60), (int)tv.tv_usec, tty->raw, tty->real_raw);
1141 /* Tell the rest of the system the news. Great news. New characters! */
1142 tty_flip_buffer_push (tty);
1143 /* tty_schedule_flip (tty); */
1149 /* Inlined: it is called only once. Remove the inline if you add another
1151 static inline void sx_check_modem_signals (struct sx_port *port)
1156 hi_state = sx_read_channel_byte (port, hi_state);
1157 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n",
1158 port->c_dcd, sx_get_CD (port));
1160 if (hi_state & ST_BREAK) {
1161 hi_state &= ~ST_BREAK;
1162 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a break.\n");
1164 sx_write_channel_byte (port, hi_state, hi_state);
1165 gs_got_break (&port->gs);
1167 if (hi_state & ST_DCD) {
1168 hi_state &= ~ST_DCD;
1169 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n");
1170 sx_write_channel_byte (port, hi_state, hi_state);
1171 c_dcd = sx_get_CD (port);
1172 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd);
1173 if (c_dcd != port->c_dcd) {
1174 port->c_dcd = c_dcd;
1175 if (sx_get_CD (port)) {
1177 if( (~(port->gs.flags & ASYNC_NORMAL_ACTIVE) ||
1178 ~(port->gs.flags & ASYNC_CALLOUT_ACTIVE)) &&
1179 (sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED) &&
1180 !(port->gs.tty->termios->c_cflag & CLOCAL) ) {
1181 /* Are we blocking in open?*/
1182 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD active, unblocking open\n");
1183 wake_up_interruptible(&port->gs.open_wait);
1185 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD raised. Ignoring.\n");
1188 /* DCD went down! */
1189 if (!((port->gs.flags & ASYNC_CALLOUT_ACTIVE) &&
1190 (port->gs.flags & ASYNC_CALLOUT_NOHUP)) &&
1191 !(port->gs.tty->termios->c_cflag & CLOCAL) ) {
1192 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. hanging up....\n");
1193 tty_hangup (port->gs.tty);
1195 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. ignoring.\n");
1199 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Hmmm. card told us DCD changed, but it didn't.\n");
1205 /* This is what an interrupt routine should look like.
1206 * Small, elegant, clear.
1209 static void sx_interrupt (int irq, void *ptr, struct pt_regs *regs)
1211 struct sx_board *board = ptr;
1212 struct sx_port *port;
1215 /* func_enter (); */
1216 sx_dprintk (SX_DEBUG_FLOW, "sx: enter sx_interrupt (%d/%d)\n", irq, board->irq);
1218 /* AAargh! The order in which to do these things is essential and
1221 - Rate limit goes before "recursive". Otherwise a series of
1222 recursive calls will hang the machine in the interrupt routine.
1224 - hardware twiddling goes before "recursive". Otherwise when we
1225 poll the card, and a recursive interrupt happens, we wont
1226 ack the card, so it might keep on interrupting us. (especially
1227 level sensitive interrupt systems like PCI).
1229 - Rate limit goes before hardware twiddling. Otherwise we won't
1230 catch a card that has gone bonkers.
1232 - The "initialized" test goes after the hardware twiddling. Otherwise
1233 the card will stick us in the interrupt routine again.
1235 - The initialized test goes before recursive.
1240 #ifdef IRQ_RATE_LIMIT
1241 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
1242 actual interrupt routine!. (Well, used to when I wrote that comment) */
1247 if (lastjif == jiffies) {
1248 if (++nintr > IRQ_RATE_LIMIT) {
1249 free_irq (board->irq, board);
1250 printk (KERN_ERR "sx: Too many interrupts. Turning off interrupt %d.\n",
1261 if (board->irq == irq) {
1262 /* Tell the card we've noticed the interrupt. */
1264 sx_write_board_word (board, cc_int_pending, 0);
1265 if (IS_SX_BOARD (board)) {
1266 write_sx_byte (board, SX_RESET_IRQ, 1);
1267 } else if (IS_EISA_BOARD(board)) {
1268 inb(board->eisa_base+0xc03);
1269 write_sx_word(board, 8, 0);
1271 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR);
1272 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
1276 if (!sx_initialized) return;
1277 if (!(board->flags & SX_BOARD_INITIALIZED)) return;
1279 if (test_and_set_bit (SX_BOARD_INTR_LOCK, &board->locks)) {
1280 printk (KERN_ERR "Recursive interrupt! (%d)\n", board->irq);
1284 for (i=0;i<board->nports;i++) {
1285 port = &board->ports[i];
1286 if (port->gs.flags & GS_ACTIVE) {
1287 if (sx_read_channel_byte (port, hi_state)) {
1288 sx_dprintk (SX_DEBUG_INTERRUPTS,
1289 "Port %d: modem signal change?... \n", i);
1290 sx_check_modem_signals (port);
1292 if (port->gs.xmit_cnt) {
1293 sx_transmit_chars (port);
1295 if (!(port->gs.flags & SX_RX_THROTTLE)) {
1296 sx_receive_chars (port);
1301 clear_bit (SX_BOARD_INTR_LOCK, &board->locks);
1303 sx_dprintk (SX_DEBUG_FLOW, "sx: exit sx_interrupt (%d/%d)\n", irq, board->irq);
1308 static void sx_pollfunc (unsigned long data)
1310 struct sx_board *board = (struct sx_board *) data;
1314 sx_interrupt (0, board, NULL);
1316 init_timer(&board->timer);
1318 board->timer.expires = jiffies + sx_poll;
1319 add_timer (&board->timer);
1325 /* ********************************************************************** *
1326 * Here are the routines that actually *
1327 * interface with the generic_serial driver *
1328 * ********************************************************************** */
1330 /* Ehhm. I don't know how to fiddle with interrupts on the SX card. --REW */
1331 /* Hmm. Ok I figured it out. You don't. */
1333 static void sx_disable_tx_interrupts (void * ptr)
1335 struct sx_port *port = ptr;
1338 port->gs.flags &= ~GS_TX_INTEN;
1344 static void sx_enable_tx_interrupts (void * ptr)
1346 struct sx_port *port = ptr;
1350 /* First transmit the characters that we're supposed to */
1351 sx_transmit_chars (port);
1353 /* The sx card will never interrupt us if we don't fill the buffer
1354 past 25%. So we keep considering interrupts off if that's the case. */
1355 data_in_buffer = (sx_read_channel_byte (port, hi_txipos) -
1356 sx_read_channel_byte (port, hi_txopos)) & 0xff;
1358 /* XXX Must be "HIGH_WATER" for SI card according to doc. */
1359 if (data_in_buffer < LOW_WATER)
1360 port->gs.flags &= ~GS_TX_INTEN;
1366 static void sx_disable_rx_interrupts (void * ptr)
1368 /* struct sx_port *port = ptr; */
1374 static void sx_enable_rx_interrupts (void * ptr)
1376 /* struct sx_port *port = ptr; */
1383 /* Jeez. Isn't this simple? */
1384 static int sx_get_CD (void * ptr)
1386 struct sx_port *port = ptr;
1390 return ((sx_read_channel_byte (port, hi_ip) & IP_DCD) != 0);
1394 /* Jeez. Isn't this simple? */
1395 static int sx_chars_in_buffer (void * ptr)
1397 struct sx_port *port = ptr;
1401 return ((sx_read_channel_byte (port, hi_txipos) -
1402 sx_read_channel_byte (port, hi_txopos)) & 0xff);
1406 static void sx_shutdown_port (void * ptr)
1408 struct sx_port *port = ptr;
1412 port->gs.flags &= ~ GS_ACTIVE;
1413 if (port->gs.tty && (port->gs.tty->termios->c_cflag & HUPCL)) {
1414 sx_setsignals (port, 0, 0);
1415 sx_reconfigure_port(port);
1425 /* ********************************************************************** *
1426 * Here are the routines that actually *
1427 * interface with the rest of the system *
1428 * ********************************************************************** */
1430 static int sx_open (struct tty_struct * tty, struct file * filp)
1432 struct sx_port *port;
1437 if (!sx_initialized) {
1441 line = MINOR(tty->device);
1442 sx_dprintk (SX_DEBUG_OPEN, "%d: opening line %d. tty=%p ctty=%p, np=%d)\n",
1443 current->pid, line, tty, current->tty, sx_nports);
1445 if ((line < 0) || (line >= SX_NPORTS) || (line >= sx_nports))
1448 port = & sx_ports[line];
1449 port->c_dcd = 0; /* Make sure that the first interrupt doesn't detect a
1450 1 -> 0 transition. */
1453 sx_dprintk (SX_DEBUG_OPEN, "port = %p c_dcd = %d\n", port, port->c_dcd);
1455 tty->driver_data = port;
1457 if (!port->gs.count)
1461 sx_dprintk (SX_DEBUG_OPEN, "starting port\n");
1464 * Start up serial port
1466 retval = gs_init_port(&port->gs);
1467 sx_dprintk (SX_DEBUG_OPEN, "done gs_init\n");
1470 if (port->gs.count) MOD_DEC_USE_COUNT;
1474 port->gs.flags |= GS_ACTIVE;
1475 sx_setsignals (port, 1,1);
1478 if (sx_debug & SX_DEBUG_OPEN)
1479 my_hd ((unsigned char *)port, sizeof (*port));
1481 if (sx_debug & SX_DEBUG_OPEN)
1482 my_hd ((unsigned char *)port->board->base + port->ch_base,
1486 if (sx_send_command (port, HS_LOPEN, -1, HS_IDLE_OPEN) != 1) {
1487 printk (KERN_ERR "sx: Card didn't respond to LOPEN command.\n");
1489 if (!port->gs.count) MOD_DEC_USE_COUNT;
1493 retval = gs_block_til_ready(port, filp);
1494 sx_dprintk (SX_DEBUG_OPEN, "Block til ready returned %d. Count=%d\n",
1495 retval, port->gs.count);
1499 * Don't lower gs.count here because sx_close() will be called later
1504 /* tty->low_latency = 1; */
1506 if ((port->gs.count == 1) && (port->gs.flags & ASYNC_SPLIT_TERMIOS)) {
1507 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
1508 *tty->termios = port->gs.normal_termios;
1510 *tty->termios = port->gs.callout_termios;
1511 sx_set_real_termios (port);
1514 port->gs.session = current->session;
1515 port->gs.pgrp = current->pgrp;
1516 port->c_dcd = sx_get_CD (port);
1517 sx_dprintk (SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd);
1524 /* I haven't the foggiest why the decrement use count has to happen
1525 here. The whole linux serial drivers stuff needs to be redesigned.
1526 My guess is that this is a hack to minimize the impact of a bug
1527 elsewhere. Thinking about it some more. (try it sometime) Try
1528 running minicom on a serial port that is driven by a modularized
1529 driver. Have the modem hangup. Then remove the driver module. Then
1530 exit minicom. I expect an "oops". -- REW */
1531 static void sx_hungup (void *ptr)
1534 struct sx_port *port = ptr;
1538 /* Don't force the SX card to close. mgetty doesn't like it !!!!!! -- pvdl */
1539 /* For some reson we added this code. Don't know why anymore ;-( -- pvdl */
1541 sx_setsignals (port, 0, 0);
1542 sx_reconfigure_port(port);
1543 sx_send_command (port, HS_CLOSE, 0, 0);
1545 if (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED) {
1546 if (sx_send_command (port, HS_FORCE_CLOSED, -1, HS_IDLE_CLOSED) != 1) {
1548 "sx: sent the force_close command, but card didn't react\n");
1550 sx_dprintk (SX_DEBUG_CLOSE, "sent the force_close command.\n");
1558 static void sx_close (void *ptr)
1560 struct sx_port *port = ptr;
1561 /* Give the port 5 seconds to close down. */
1566 sx_setsignals (port, 0, 0);
1567 sx_reconfigure_port(port);
1568 sx_send_command (port, HS_CLOSE, 0, 0);
1570 while (to-- && (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED)) {
1571 current->state = TASK_INTERRUPTIBLE;
1572 schedule_timeout (1);
1573 if (signal_pending (current))
1576 current->state = TASK_RUNNING;
1577 if (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED) {
1578 if (sx_send_command (port, HS_FORCE_CLOSED, -1, HS_IDLE_CLOSED) != 1) {
1580 "sx: sent the force_close command, but card didn't react\n");
1582 sx_dprintk (SX_DEBUG_CLOSE, "sent the force_close command.\n");
1585 sx_dprintk (SX_DEBUG_CLOSE, "waited %d jiffies for close. count=%d\n",
1586 5 * HZ - to - 1, port->gs.count);
1588 if(port->gs.count) {
1589 sx_dprintk(SX_DEBUG_CLOSE, "WARNING port count:%d\n", port->gs.count);
1599 /* This is relatively thorough. But then again it is only 20 lines. */
1600 #define MARCHUP for (i=min;i<max;i++)
1601 #define MARCHDOWN for (i=max-1;i>=min;i--)
1602 #define W0 write_sx_byte (board, i, 0x55)
1603 #define W1 write_sx_byte (board, i, 0xaa)
1604 #define R0 if (read_sx_byte (board, i) != 0x55) return 1
1605 #define R1 if (read_sx_byte (board, i) != 0xaa) return 1
1607 /* This memtest takes a human-noticable time. You normally only do it
1608 once a boot, so I guess that it is worth it. */
1609 static int do_memtest (struct sx_board *board, int min, int max)
1613 /* This is a marchb. Theoretically, marchb catches much more than
1614 simpler tests. In practise, the longer test just catches more
1615 intermittent errors. -- REW
1616 (For the theory behind memory testing see:
1617 Testing Semiconductor Memories by A.J. van de Goor.) */
1619 MARCHUP {R0;W1;R1;W0;R0;W1;}
1621 MARCHDOWN {R1;W0;W1;W0;}
1622 MARCHDOWN {R0;W1;W0;}
1635 #define MARCHUP for (i=min;i<max;i+=2)
1636 #define MARCHDOWN for (i=max-1;i>=min;i-=2)
1637 #define W0 write_sx_word (board, i, 0x55aa)
1638 #define W1 write_sx_word (board, i, 0xaa55)
1639 #define R0 if (read_sx_word (board, i) != 0x55aa) return 1
1640 #define R1 if (read_sx_word (board, i) != 0xaa55) return 1
1643 /* This memtest takes a human-noticable time. You normally only do it
1644 once a boot, so I guess that it is worth it. */
1645 static int do_memtest_w (struct sx_board *board, int min, int max)
1650 MARCHUP {R0;W1;R1;W0;R0;W1;}
1652 MARCHDOWN {R1;W0;W1;W0;}
1653 MARCHDOWN {R0;W1;W0;}
1660 static int sx_fw_ioctl (struct inode *inode, struct file *filp,
1661 unsigned int cmd, unsigned long arg)
1664 int *descr = (int *)arg, i;
1665 static struct sx_board *board = NULL;
1673 /* Removed superuser check: Sysops can use the permissions on the device
1674 file to restrict access. Recommendation: Root only. (root.root 600) */
1675 if (!capable(CAP_SYS_ADMIN)) {
1680 sx_dprintk (SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg);
1682 if (!board) board = &boards[0];
1683 if (board->flags & SX_BOARD_PRESENT) {
1684 sx_dprintk (SX_DEBUG_FIRMWARE, "Board present! (%x)\n",
1687 sx_dprintk (SX_DEBUG_FIRMWARE, "Board not present! (%x) all:",
1689 for (i=0;i< SX_NBOARDS;i++)
1690 sx_dprintk (SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags);
1691 sx_dprintk (SX_DEBUG_FIRMWARE, "\n");
1696 case SXIO_SET_BOARD:
1697 sx_dprintk (SX_DEBUG_FIRMWARE, "set board to %ld\n", arg);
1698 if (arg > SX_NBOARDS) return -EIO;
1699 sx_dprintk (SX_DEBUG_FIRMWARE, "not out of range\n");
1700 if (!(boards[arg].flags & SX_BOARD_PRESENT)) return -EIO;
1701 sx_dprintk (SX_DEBUG_FIRMWARE, ".. and present!\n");
1702 board = &boards[arg];
1705 rc = -ENOENT; /* If we manage to miss one, return error. */
1706 if (IS_SX_BOARD (board)) rc = SX_TYPE_SX;
1707 if (IS_CF_BOARD (board)) rc = SX_TYPE_CF;
1708 if (IS_SI_BOARD (board)) rc = SX_TYPE_SI;
1709 if (IS_SI1_BOARD (board)) rc = SX_TYPE_SI;
1710 if (IS_EISA_BOARD (board)) rc = SX_TYPE_SI;
1711 sx_dprintk (SX_DEBUG_FIRMWARE, "returning type= %d\n", rc);
1713 case SXIO_DO_RAMTEST:
1714 if (sx_initialized) /* Already initialized: better not ramtest the board. */
1716 if (IS_SX_BOARD (board)) {
1717 rc = do_memtest (board, 0, 0x7000);
1718 if (!rc) rc = do_memtest (board, 0, 0x7000);
1719 /*if (!rc) rc = do_memtest_w (board, 0, 0x7000);*/
1721 rc = do_memtest (board, 0, 0x7ff8);
1722 /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */
1724 sx_dprintk (SX_DEBUG_FIRMWARE, "returning memtest result= %d\n", rc);
1727 if (sx_initialized) /* Already initialized */
1729 if (!sx_reset (board))
1731 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
1733 tmp = kmalloc (SX_CHUNK_SIZE, GFP_USER);
1734 if (!tmp) return -ENOMEM;
1735 Get_user (nbytes, descr++);
1736 Get_user (offset, descr++);
1737 Get_user (data, descr++);
1738 while (nbytes && data) {
1739 for (i=0;i<nbytes;i += SX_CHUNK_SIZE) {
1740 if (copy_from_user(tmp, (char *)data + i,
1741 (i + SX_CHUNK_SIZE >
1742 nbytes) ? nbytes - i :
1745 memcpy_toio ((char *) (board->base2 + offset + i), tmp,
1746 (i+SX_CHUNK_SIZE>nbytes)?nbytes-i:SX_CHUNK_SIZE);
1749 Get_user (nbytes, descr++);
1750 Get_user (offset, descr++);
1751 Get_user (data, descr++);
1754 sx_nports += sx_init_board (board);
1758 if (sx_initialized) /* Already initialized */
1760 /* This is not allowed until all boards are initialized... */
1761 for (i=0;i<SX_NBOARDS;i++) {
1762 if ( (boards[i].flags & SX_BOARD_PRESENT) &&
1763 !(boards[i].flags & SX_BOARD_INITIALIZED))
1766 for (i=0;i<SX_NBOARDS;i++)
1767 if (!(boards[i].flags & SX_BOARD_PRESENT)) break;
1769 sx_dprintk (SX_DEBUG_FIRMWARE, "initing portstructs, %d boards, "
1770 "%d channels, first board: %d ports\n",
1771 i, sx_nports, boards[0].nports);
1772 rc = sx_init_portstructs (i, sx_nports);
1783 case SXIO_GETGSDEBUG:
1784 case SXIO_SETGSDEBUG:
1787 case SXIO_GETNPORTS:
1791 printk (KERN_WARNING "Unknown ioctl on firmware device (%x).\n", cmd);
1799 static void sx_break (struct tty_struct * tty, int flag)
1801 struct sx_port *port = tty->driver_data;
1805 rv = sx_send_command (port, HS_START, -1, HS_IDLE_BREAK);
1807 rv = sx_send_command (port, HS_STOP, -1, HS_IDLE_OPEN);
1808 if (rv != 1) printk (KERN_ERR "sx: couldn't send break (%x).\n",
1809 read_sx_byte (port->board, CHAN_OFFSET (port, hi_hstat)));
1813 static int sx_ioctl (struct tty_struct * tty, struct file * filp,
1814 unsigned int cmd, unsigned long arg)
1817 struct sx_port *port = tty->driver_data;
1820 /* func_enter2(); */
1825 rc = Put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1826 (unsigned int *) arg);
1829 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1830 sizeof(int))) == 0) {
1831 Get_user(ival, (unsigned int *) arg);
1832 tty->termios->c_cflag =
1833 (tty->termios->c_cflag & ~CLOCAL) |
1834 (ival ? CLOCAL : 0);
1838 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1839 sizeof(struct serial_struct))) == 0)
1840 rc = gs_getserial(&port->gs, (struct serial_struct *) arg);
1843 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1844 sizeof(struct serial_struct))) == 0)
1845 rc = gs_setserial(&port->gs, (struct serial_struct *) arg);
1848 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1849 sizeof(unsigned int))) == 0) {
1850 ival = sx_getsignals(port);
1851 put_user(ival, (unsigned int *) arg);
1855 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1856 sizeof(unsigned int))) == 0) {
1857 Get_user(ival, (unsigned int *) arg);
1858 sx_setsignals(port, ((ival & TIOCM_DTR) ? 1 : -1),
1859 ((ival & TIOCM_RTS) ? 1 : -1));
1860 sx_reconfigure_port(port);
1864 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1865 sizeof(unsigned int))) == 0) {
1866 Get_user(ival, (unsigned int *) arg);
1867 sx_setsignals(port, ((ival & TIOCM_DTR) ? 0 : -1),
1868 ((ival & TIOCM_RTS) ? 0 : -1));
1869 sx_reconfigure_port(port);
1873 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1874 sizeof(unsigned int))) == 0) {
1875 Get_user(ival, (unsigned int *) arg);
1876 sx_setsignals(port, ((ival & TIOCM_DTR) ? 1 : 0),
1877 ((ival & TIOCM_RTS) ? 1 : 0));
1878 sx_reconfigure_port(port);
1891 /* The throttle/unthrottle scheme for the Specialix card is different
1892 * from other drivers and deserves some explanation.
1893 * The Specialix hardware takes care of XON/XOFF
1894 * and CTS/RTS flow control itself. This means that all we have to
1895 * do when signalled by the upper tty layer to throttle/unthrottle is
1896 * to make a note of it here. When we come to read characters from the
1897 * rx buffers on the card (sx_receive_chars()) we look to see if the
1898 * upper layer can accept more (as noted here in sx_rx_throt[]).
1899 * If it can't we simply don't remove chars from the cards buffer.
1900 * When the tty layer can accept chars, we again note that here and when
1901 * sx_receive_chars() is called it will remove them from the cards buffer.
1902 * The card will notice that a ports buffer has drained below some low
1903 * water mark and will unflow control the line itself, using whatever
1904 * flow control scheme is in use for that port. -- Simon Allen
1907 static void sx_throttle (struct tty_struct * tty)
1909 struct sx_port *port = (struct sx_port *)tty->driver_data;
1912 /* If the port is using any type of input flow
1913 * control then throttle the port.
1915 if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) {
1916 port->gs.flags |= SX_RX_THROTTLE;
1922 static void sx_unthrottle (struct tty_struct * tty)
1924 struct sx_port *port = (struct sx_port *)tty->driver_data;
1927 /* Always unthrottle even if flow control is not enabled on
1928 * this port in case we disabled flow control while the port
1931 port->gs.flags &= ~SX_RX_THROTTLE;
1937 /* ********************************************************************** *
1938 * Here are the initialization routines. *
1939 * ********************************************************************** */
1944 static int sx_init_board (struct sx_board *board)
1952 /* This is preceded by downloading the download code. */
1954 board->flags |= SX_BOARD_INITIALIZED;
1956 if (read_sx_byte (board, 0))
1957 /* CF boards may need this. */
1958 write_sx_byte(board,0, 0);
1960 /* This resets the processor again, to make sure it didn't do any
1961 foolish things while we were downloading the image */
1962 if (!sx_reset (board))
1965 sx_start_board (board);
1967 if (!sx_busy_wait_neq (board, 0, 0xff, 0)) {
1968 printk (KERN_ERR "sx: Ooops. Board won't initialize.\n");
1972 /* Ok. So now the processor on the card is running. It gathered
1973 some info for us... */
1974 sx_dprintk (SX_DEBUG_INIT, "The sxcard structure:\n");
1975 if (sx_debug & SX_DEBUG_INIT) my_hd ((char *)(board->base), 0x10);
1976 sx_dprintk (SX_DEBUG_INIT, "the first sx_module structure:\n");
1977 if (sx_debug & SX_DEBUG_INIT) my_hd ((char *)(board->base + 0x80), 0x30);
1979 sx_dprintk (SX_DEBUG_INIT,
1980 "init_status: %x, %dk memory, firmware V%x.%02x,\n",
1981 read_sx_byte (board, 0), read_sx_byte(board, 1),
1982 read_sx_byte (board, 5), read_sx_byte(board, 4));
1984 if (read_sx_byte (board, 0) == 0xff) {
1985 printk (KERN_INFO "sx: No modules found. Sorry.\n");
1992 if (IS_SX_BOARD(board)) {
1993 sx_write_board_word (board, cc_int_count, sx_maxints);
1996 sx_write_board_word (board, cc_int_count, SI_PROCESSOR_CLOCK/8/sx_maxints);
1999 /* grab the first module type... */
2000 /* board->ta_type = mod_compat_type (read_sx_byte (board, 0x80 + 0x08)); */
2001 board->ta_type = mod_compat_type (sx_read_module_byte (board, 0x80, mc_chip));
2004 for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) {
2005 type = sx_read_module_byte (board, addr, mc_chip);
2006 sx_dprintk (SX_DEBUG_INIT, "Module at %x: %d channels\n",
2007 addr, read_sx_byte (board, addr + 2));
2009 chans += sx_read_module_byte (board, addr, mc_type);
2011 sx_dprintk (SX_DEBUG_INIT, "module is an %s, which has %s/%s panels\n",
2013 pan_type_s (sx_read_module_byte (board, addr, mc_mods) & 0xf),
2014 pan_type_s (sx_read_module_byte (board, addr, mc_mods) >> 4));
2016 sx_dprintk (SX_DEBUG_INIT, "CD1400 versions: %x/%x, ASIC version: %x\n",
2017 sx_read_module_byte (board, addr, mc_rev1),
2018 sx_read_module_byte (board, addr, mc_rev2),
2019 sx_read_module_byte (board, addr, mc_mtaasic_rev));
2021 /* The following combinations are illegal: It should theoretically
2022 work, but timing problems make the bus HANG. */
2024 if (mod_compat_type (type) != board->ta_type) {
2025 printk (KERN_ERR "sx: This is an invalid configuration.\n"
2026 "Don't mix TA/MTA/SXDC on the same hostadapter.\n");
2030 if ((IS_EISA_BOARD(board) ||
2031 IS_SI_BOARD(board)) && (mod_compat_type(type) == 4)) {
2032 printk (KERN_ERR "sx: This is an invalid configuration.\n"
2033 "Don't use SXDCs on an SI/XIO adapter.\n");
2037 #if 0 /* Problem fixed: firmware 3.05 */
2038 if (IS_SX_BOARD(board) && (type == TA8)) {
2039 /* There are some issues with the firmware and the DCD/RTS
2040 lines. It might work if you tie them together or something.
2041 It might also work if you get a newer sx_firmware. Therefore
2042 this is just a warning. */
2043 printk (KERN_WARNING "sx: The SX host doesn't work too well "
2044 "with the TA8 adapters.\nSpecialix is working on it.\n");
2050 /* board->flags |= SX_BOARD_PRESENT; */
2051 if(board->irq > 0) {
2052 /* fixed irq, probably PCI */
2053 if(sx_irqmask & (1 << board->irq)) { /* may we use this irq? */
2054 if(request_irq(board->irq, sx_interrupt, SA_SHIRQ | SA_INTERRUPT, "sx", board)) {
2055 printk(KERN_ERR "sx: Cannot allocate irq %d.\n", board->irq);
2060 } else if(board->irq < 0 && sx_irqmask) {
2061 /* auto-allocate irq */
2063 int irqmask = sx_irqmask & (IS_SX_BOARD(board) ? SX_ISA_IRQ_MASK : SI2_ISA_IRQ_MASK);
2064 for(irqnr = 15; irqnr > 0; irqnr--)
2065 if(irqmask & (1 << irqnr))
2066 if(! request_irq(irqnr, sx_interrupt, SA_SHIRQ | SA_INTERRUPT, "sx", board))
2069 printk(KERN_ERR "sx: Cannot allocate IRQ.\n");
2075 /* Found a valid interrupt, start up interrupts! */
2076 sx_dprintk (SX_DEBUG_INIT, "Using irq %d.\n", board->irq);
2077 sx_start_interrupts (board);
2078 board->poll = sx_slowpoll;
2079 board->flags |= SX_IRQ_ALLOCATED;
2081 /* no irq: setup board for polled operation */
2082 board->poll = sx_poll;
2083 sx_dprintk (SX_DEBUG_INIT, "Using poll-interval %d.\n", board->poll);
2086 /* The timer should be initialized anyway: That way we can safely
2087 del_timer it when the module is unloaded. */
2088 init_timer (&board->timer);
2091 board->timer.data = (unsigned long) board;
2092 board->timer.function = sx_pollfunc;
2093 board->timer.expires = jiffies + board->poll;
2094 add_timer (&board->timer);
2100 board->nports = chans;
2101 sx_dprintk (SX_DEBUG_INIT, "returning %d ports.", board->nports);
2108 static void printheader(void)
2110 static int header_printed;
2112 if (!header_printed) {
2113 printk (KERN_INFO "Specialix SX driver "
2114 "(C) 1998/1999 R.E.Wolff@BitWizard.nl \n");
2115 printk (KERN_INFO "sx: version %s\n", RCS_ID);
2121 static int probe_sx (struct sx_board *board)
2123 struct vpd_prom vpdp;
2129 if (!IS_CF_BOARD (board)) {
2130 sx_dprintk (SX_DEBUG_PROBE, "Going to verify vpd prom at %lx.\n",
2131 board->base + SX_VPD_ROM);
2133 if (sx_debug & SX_DEBUG_PROBE)
2134 my_hd ((char *)(board->base + SX_VPD_ROM), 0x40);
2137 for (i=0;i< sizeof (struct vpd_prom);i++)
2138 *p++ = read_sx_byte (board, SX_VPD_ROM + i*2);
2140 if (sx_debug & SX_DEBUG_PROBE)
2141 my_hd ((char *)&vpdp, 0x20);
2143 sx_dprintk (SX_DEBUG_PROBE, "checking identifier...\n");
2145 if (strncmp (vpdp.identifier, SX_VPD_IDENT_STRING, 16) != 0) {
2146 sx_dprintk (SX_DEBUG_PROBE, "Got non-SX identifier: '%s'\n",
2154 if (!IS_CF_BOARD (board)) {
2155 printk (KERN_DEBUG "sx: Found an SX board at %lx\n", board->hw_base);
2156 printk (KERN_DEBUG "sx: hw_rev: %d, assembly level: %d, uniq ID:%08x, ",
2157 vpdp.hwrev, vpdp.hwass, vpdp.uniqid);
2158 printk ( "Manufactured: %d/%d\n",
2159 1970 + vpdp.myear, vpdp.mweek);
2162 if ((((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_PCI_UNIQUEID1) &&
2163 (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_ISA_UNIQUEID1)) {
2164 /* This might be a bit harsh. This was the primary reason the
2165 SX/ISA card didn't work at first... */
2166 printk (KERN_ERR "sx: Hmm. Not an SX/PCI or SX/ISA card. Sorry: giving up.\n");
2170 if (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) == SX_ISA_UNIQUEID1) {
2171 if (board->base & 0x8000) {
2172 printk (KERN_WARNING "sx: Warning: There may be hardware problems with the card at %lx.\n", board->base);
2173 printk (KERN_WARNING "sx: Read sx.txt for more info.\n");
2180 /* This resets the processor, and keeps it off the bus. */
2181 if (!sx_reset (board))
2183 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
2185 board->flags |= SX_BOARD_PRESENT;
2193 /* Specialix probes for this card at 32k increments from 640k to 16M.
2194 I consider machines with less than 16M unlikely nowadays, so I'm
2195 not probing above 1Mb. Also, 0xa0000, 0xb0000, are taken by the VGA
2196 card. 0xe0000 and 0xf0000 are taken by the BIOS. That only leaves
2197 0xc0000, 0xc8000, 0xd0000 and 0xd8000 . */
2199 static int probe_si (struct sx_board *board)
2204 sx_dprintk (SX_DEBUG_PROBE, "Going to verify SI signature hw %lx at %lx.\n", board->hw_base,
2205 board->base + SI2_ISA_ID_BASE);
2207 if (sx_debug & SX_DEBUG_PROBE)
2208 my_hd ((char *)(board->base + SI2_ISA_ID_BASE), 0x8);
2210 if (!IS_EISA_BOARD(board) ) {
2211 if( IS_SI1_BOARD(board) )
2214 write_sx_byte (board, SI2_ISA_ID_BASE+7-i,i);
2219 if ((read_sx_byte (board, SI2_ISA_ID_BASE+7-i) & 7) != i) {
2225 /* Now we're pretty much convinced that there is an SI board here,
2226 but to prevent trouble, we'd better double check that we don't
2227 have an SI1 board when we're probing for an SI2 board.... */
2229 write_sx_byte (board, SI2_ISA_ID_BASE,0x10);
2230 if ( IS_SI1_BOARD(board)) {
2231 /* This should be an SI1 board, which has this
2232 location writable... */
2233 if (read_sx_byte (board, SI2_ISA_ID_BASE) != 0x10)
2236 /* This should be an SI2 board, which has the bottom
2237 3 bits non-writable... */
2238 if (read_sx_byte (board, SI2_ISA_ID_BASE) == 0x10)
2244 printk (KERN_DEBUG "sx: Found an SI board at %lx\n", board->hw_base);
2245 /* Compared to the SX boards, it is a complete guess as to what
2246 this card is up to... */
2250 /* This resets the processor, and keeps it off the bus. */
2251 if (!sx_reset (board))
2253 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
2255 board->flags |= SX_BOARD_PRESENT;
2262 static int sx_init_drivers(void)
2268 memset(&sx_driver, 0, sizeof(sx_driver));
2269 sx_driver.magic = TTY_DRIVER_MAGIC;
2270 sx_driver.driver_name = "specialix_sx";
2271 sx_driver.name = "ttyX";
2272 sx_driver.major = SX_NORMAL_MAJOR;
2273 sx_driver.num = sx_nports;
2274 sx_driver.type = TTY_DRIVER_TYPE_SERIAL;
2275 sx_driver.subtype = SX_TYPE_NORMAL;
2276 sx_driver.init_termios = tty_std_termios;
2277 sx_driver.init_termios.c_cflag =
2278 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2279 sx_driver.flags = TTY_DRIVER_REAL_RAW;
2280 sx_driver.refcount = &sx_refcount;
2281 sx_driver.table = sx_table;
2282 sx_driver.termios = sx_termios;
2283 sx_driver.termios_locked = sx_termios_locked;
2284 sx_driver.break_ctl = sx_break;
2286 sx_driver.open = sx_open;
2287 sx_driver.close = gs_close;
2288 sx_driver.write = gs_write;
2289 sx_driver.put_char = gs_put_char;
2290 sx_driver.flush_chars = gs_flush_chars;
2291 sx_driver.write_room = gs_write_room;
2292 sx_driver.chars_in_buffer = gs_chars_in_buffer;
2293 sx_driver.flush_buffer = gs_flush_buffer;
2294 sx_driver.ioctl = sx_ioctl;
2295 sx_driver.throttle = sx_throttle;
2296 sx_driver.unthrottle = sx_unthrottle;
2297 sx_driver.set_termios = gs_set_termios;
2298 sx_driver.stop = gs_stop;
2299 sx_driver.start = gs_start;
2300 sx_driver.hangup = gs_hangup;
2302 sx_callout_driver = sx_driver;
2303 sx_callout_driver.name = "cux";
2304 sx_callout_driver.major = SX_CALLOUT_MAJOR;
2305 sx_callout_driver.subtype = SX_TYPE_CALLOUT;
2307 if ((error = tty_register_driver(&sx_driver))) {
2308 printk(KERN_ERR "sx: Couldn't register sx driver, error = %d\n",
2312 if ((error = tty_register_driver(&sx_callout_driver))) {
2313 tty_unregister_driver(&sx_driver);
2314 printk(KERN_ERR "sx: Couldn't register sx callout driver, error = %d\n",
2324 static void * ckmalloc (int size)
2328 p = kmalloc(size, GFP_KERNEL);
2335 static int sx_init_portstructs (int nboards, int nports)
2337 struct sx_board *board;
2338 struct sx_port *port;
2345 /* Many drivers statically allocate the maximum number of ports
2346 There is no reason not to allocate them dynamically. Is there? -- REW */
2347 sx_ports = ckmalloc(nports * sizeof (struct sx_port));
2351 sx_termios = ckmalloc(nports * sizeof (struct termios *));
2357 sx_termios_locked = ckmalloc(nports * sizeof (struct termios *));
2358 if (!sx_termios_locked) {
2364 /* Adjust the values in the "driver" */
2365 sx_driver.termios = sx_termios;
2366 sx_driver.termios_locked = sx_termios_locked;
2369 for (i = 0; i < nboards; i++) {
2371 board->ports = port;
2372 for (j=0; j < boards[i].nports;j++) {
2373 sx_dprintk (SX_DEBUG_INIT, "initing port %d\n", j);
2374 port->gs.callout_termios = tty_std_termios;
2375 port->gs.normal_termios = tty_std_termios;
2376 port->gs.magic = SX_MAGIC;
2377 port->gs.close_delay = HZ/2;
2378 port->gs.closing_wait = 30 * HZ;
2379 port->board = board;
2380 port->gs.rd = &sx_real_driver;
2381 #ifdef NEW_WRITE_LOCKING
2382 port->gs.port_write_sem = MUTEX;
2385 * Initializing wait queue
2387 init_waitqueue_head(&port->gs.open_wait);
2388 init_waitqueue_head(&port->gs.close_wait);
2396 for (i = 0; i < nboards; i++) {
2398 board->port_base = portno;
2399 /* Possibly the configuration was rejected. */
2400 sx_dprintk (SX_DEBUG_PROBE, "Board has %d channels\n", board->nports);
2401 if (board->nports <= 0) continue;
2402 /* XXX byteorder ?? */
2403 for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) {
2404 chans = sx_read_module_byte (board, addr, mc_type);
2405 sx_dprintk (SX_DEBUG_PROBE, "Module at %x: %d channels\n", addr, chans);
2406 sx_dprintk (SX_DEBUG_PROBE, "Port at");
2407 for (j=0;j<chans;j++) {
2408 /* The "sx-way" is the way it SHOULD be done. That way in the
2409 future, the firmware may for example pack the structures a bit
2410 more efficient. Neil tells me it isn't going to happen anytime
2412 if (IS_SX_BOARD(board))
2413 port->ch_base = sx_read_module_word (board, addr+j*2, mc_chan_pointer);
2415 port->ch_base = addr + 0x100 + 0x300*j;
2417 sx_dprintk (SX_DEBUG_PROBE, " %x", port->ch_base);
2418 port->line = portno++;
2421 sx_dprintk (SX_DEBUG_PROBE, "\n");
2423 /* This has to be done earlier. */
2424 /* board->flags |= SX_BOARD_INITIALIZED; */
2431 static void __exit sx_release_drivers(void)
2434 tty_unregister_driver(&sx_driver);
2435 tty_unregister_driver(&sx_callout_driver);
2440 #define PDEV unsigned char pci_bus, unsigned pci_fun
2441 #define pdev pci_bus, pci_fun
2443 #define PDEV struct pci_dev *pdev
2448 /********************************************************
2449 * Setting bit 17 in the CNTRL register of the PLX 9050 *
2450 * chip forces a retry on writes while a read is pending.*
2451 * This is to prevent the card locking up on Intel Xeon *
2452 * multiprocessor systems with the NX chipset. -- NV *
2453 ********************************************************/
2455 /* Newer cards are produced with this bit set from the configuration
2456 EEprom. As the bit is read/write for the CPU, we can fix it here,
2457 if we detect that it isn't set correctly. -- REW */
2459 static void fix_sx_pci (PDEV, struct sx_board *board)
2461 unsigned int hwbase;
2462 unsigned long rebase;
2465 #define CNTRL_REG_OFFSET 0x50
2466 #define CNTRL_REG_GOODVALUE 0x18260000
2468 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
2469 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
2470 rebase = (ulong) ioremap(hwbase, 0x80);
2471 t = readl (rebase + CNTRL_REG_OFFSET);
2472 if (t != CNTRL_REG_GOODVALUE) {
2473 printk (KERN_DEBUG "sx: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
2474 writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
2476 my_iounmap (hwbase, rebase);
2481 static int __init sx_init(void)
2486 struct sx_board *board;
2490 struct pci_dev *pdev = NULL;
2492 unsigned char pci_bus, pci_fun;
2493 /* in 2.2.x pdev is a pointer defining a PCI device. In 2.0 its the bus/fn */
2496 unsigned short tshort;
2500 sx_dprintk (SX_DEBUG_INIT, "Initing sx module... (sx_debug=%d)\n", sx_debug);
2501 if (abs ((long) (&sx_debug) - sx_debug) < 0x10000) {
2502 printk (KERN_WARNING "sx: sx_debug is an address, instead of a value. "
2504 printk ("(%p)\n", &sx_debug);
2509 if (pci_present ()) {
2511 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
2512 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
2514 if (pci_enable_device(pdev))
2517 for (i=0;i< SX_NBOARDS;i++) {
2518 if (pcibios_find_device (PCI_VENDOR_ID_SPECIALIX,
2519 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, i,
2520 &pci_bus, &pci_fun)) break;
2522 /* Specialix has a whole bunch of cards with
2523 0x2000 as the device ID. They say its because
2524 the standard requires it. Stupid standard. */
2525 /* It seems that reading a word doesn't work reliably on 2.0.
2526 Also, reading a non-aligned dword doesn't work. So we read the
2527 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
2529 /* I don't know why the define doesn't work, constant 0x2c does --REW */
2530 pci_read_config_dword (pdev, 0x2c, &tint);
2531 tshort = (tint >> 16) & 0xffff;
2532 sx_dprintk (SX_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
2533 /* sx_dprintk (SX_DEBUG_PROBE, "pdev = %d/%d (%x)\n", pdev, tint); */
2534 if ((tshort != 0x0200) && (tshort != 0x0300)) {
2535 sx_dprintk (SX_DEBUG_PROBE, "But it's not an SX card (%d)...\n",
2539 board = &boards[found];
2541 board->flags &= ~SX_BOARD_TYPE;
2542 board->flags |= (tshort == 0x200)?SX_PCI_BOARD:
2545 /* CF boards use base address 3.... */
2546 if (IS_CF_BOARD (board))
2547 board->hw_base = pci_resource_start (pdev, 3);
2549 board->hw_base = pci_resource_start (pdev, 2);
2551 board->base = (ulong) ioremap(board->hw_base, WINDOW_LEN (board));
2553 printk(KERN_ERR "ioremap failed\n");
2554 /* XXX handle error */
2557 /* Most of the stuff on the CF board is offset by
2559 if (IS_CF_BOARD (board)) board->base += 0x18000;
2561 board->irq = get_irq (pdev);
2563 sx_dprintk (SX_DEBUG_PROBE, "Got a specialix card: %x/%lx(%d) %x.\n",
2564 tint, boards[found].base, board->irq, board->flags);
2566 if (probe_sx (board)) {
2568 fix_sx_pci (pdev, board);
2570 my_iounmap (board->hw_base, board->base);
2575 for (i=0;i<NR_SX_ADDRS;i++) {
2576 board = &boards[found];
2577 board->hw_base = sx_probe_addrs[i];
2579 board->base = (ulong) ioremap(board->hw_base, SX_WINDOW_LEN);
2580 board->flags &= ~SX_BOARD_TYPE;
2581 board->flags |= SX_ISA_BOARD;
2582 board->irq = sx_irqmask?-1:0;
2584 if (probe_sx (board)) {
2587 my_iounmap (board->hw_base, board->base);
2591 for (i=0;i<NR_SI_ADDRS;i++) {
2592 board = &boards[found];
2593 board->hw_base = si_probe_addrs[i];
2595 board->base = (ulong) ioremap(board->hw_base, SI2_ISA_WINDOW_LEN);
2596 board->flags &= ~SX_BOARD_TYPE;
2597 board->flags |= SI_ISA_BOARD;
2598 board->irq = sx_irqmask ?-1:0;
2600 if (probe_si (board)) {
2603 my_iounmap (board->hw_base, board->base);
2606 for (i=0;i<NR_SI1_ADDRS;i++) {
2607 board = &boards[found];
2608 board->hw_base = si1_probe_addrs[i];
2610 board->base = (ulong) ioremap(board->hw_base, SI1_ISA_WINDOW_LEN);
2611 board->flags &= ~SX_BOARD_TYPE;
2612 board->flags |= SI1_ISA_BOARD;
2613 board->irq = sx_irqmask ?-1:0;
2615 if (probe_si (board)) {
2618 my_iounmap (board->hw_base, board->base);
2622 sx_dprintk(SX_DEBUG_PROBE, "Probing for EISA cards\n");
2623 for(eisa_slot=0x1000; eisa_slot<0x10000; eisa_slot+=0x1000)
2625 if((inb(eisa_slot+0xc80)==0x4d) &&
2626 (inb(eisa_slot+0xc81)==0x98))
2628 sx_dprintk(SX_DEBUG_PROBE, "%s : Signature found in EISA slot %d, Product %d Rev %d\n",
2629 "XIO", (eisa_slot>>12), inb(eisa_slot+0xc82), inb(eisa_slot+0xc83));
2631 board = &boards[found];
2632 board->eisa_base = eisa_slot;
2633 board->flags &= ~SX_BOARD_TYPE;
2634 board->flags |= SI_EISA_BOARD;
2636 board->hw_base = (((inb(0xc01+eisa_slot) << 8) + inb(0xc00+eisa_slot)) << 16);
2638 board->base = (ulong) ioremap(board->hw_base, SI2_EISA_WINDOW_LEN);
2640 sx_dprintk(SX_DEBUG_PROBE, "IO hw_base address: %lx\n", board->hw_base);
2641 sx_dprintk(SX_DEBUG_PROBE, "base: %lx\n", board->base);
2642 board->irq = inb(board->eisa_base+0xc02)>>4;
2643 sx_dprintk(SX_DEBUG_PROBE, "IRQ: %d\n", board->irq);
2651 printk (KERN_INFO "sx: total of %d boards detected.\n", found);
2653 if (misc_register(&sx_fw_device) < 0) {
2654 printk(KERN_ERR "SX: Unable to register firmware loader driver.\n");
2660 return found?0:-EIO;
2664 static void __exit sx_exit (void)
2667 struct sx_board *board;
2670 for (i = 0; i < SX_NBOARDS; i++) {
2672 if (board->flags & SX_BOARD_INITIALIZED) {
2673 sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up board at %lx\n", board->base);
2674 /* The board should stop messing with us.
2675 (actually I mean the interrupt) */
2677 if ((board->irq) && (board->flags & SX_IRQ_ALLOCATED))
2678 free_irq (board->irq, board);
2680 /* It is safe/allowed to del_timer a non-active timer */
2681 del_timer (& board->timer);
2682 my_iounmap (board->hw_base, board->base);
2685 if (misc_deregister(&sx_fw_device) < 0) {
2686 printk (KERN_INFO "sx: couldn't deregister firmware loader device\n");
2688 sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up drivers (%d)\n", sx_initialized);
2690 sx_release_drivers ();
2694 kfree (sx_termios_locked);
2698 module_init(sx_init);
2699 module_exit(sx_exit);