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 - 2004 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,
35 * Revision 1.33 2000/03/09 10:00:00 pvdl,wolff
36 * - Fixed module and port counting
37 * - Fixed signal handling
40 * Revision 1.32 2000/03/07 09:00:00 wolff,pvdl
41 * - Fixed some sx_dprintk typos
42 * - added detection for an invalid board/module configuration
44 * Revision 1.31 2000/03/06 12:00:00 wolff,pvdl
45 * - Added support for EISA
47 * Revision 1.30 2000/01/21 17:43:06 wolff
48 * - Added support for SX+
50 * Revision 1.26 1999/08/05 15:22:14 wolff
52 * - Reformatted to Linus' liking.
54 * Revision 1.25 1999/07/30 14:24:08 wolff
55 * Had accidentally left "gs_debug" set to "-1" instead of "off" (=0).
57 * Revision 1.24 1999/07/28 09:41:52 wolff
58 * - I noticed the remark about use-count straying in sx.txt. I checked
59 * sx_open, and found a few places where that could happen. I hope it's
62 * Revision 1.23 1999/07/28 08:56:06 wolff
63 * - Fixed crash when sx_firmware run twice.
64 * - Added sx_slowpoll as a module parameter (I guess nobody really wanted
65 * to change it from the default... )
66 * - Fixed a stupid editing problem I introduced in 1.22.
67 * - Fixed dropping characters on a termios change.
69 * Revision 1.22 1999/07/26 21:01:43 wolff
70 * Russell Brown noticed that I had overlooked 4 out of six modem control
71 * signals in sx_getsignals. Ooops.
73 * Revision 1.21 1999/07/23 09:11:33 wolff
74 * I forgot to free dynamically allocated memory when the driver is unloaded.
76 * Revision 1.20 1999/07/20 06:25:26 wolff
77 * The "closing wait" wasn't honoured. Thanks to James Griffiths for
80 * Revision 1.19 1999/07/11 08:59:59 wolff
81 * Fixed an oops in close, when an open was pending. Changed the memtest
82 * a bit. Should also test the board in word-mode, however my card fails the
83 * memtest then. I still have to figure out what is wrong...
85 * Revision 1.18 1999/06/10 09:38:42 wolff
86 * Changed the format of the firmware revision from %04x to %x.%02x .
88 * Revision 1.17 1999/06/04 09:44:35 wolff
89 * fixed problem: reference to pci stuff when config_pci was off...
90 * Thanks to Jorge Novo for noticing this.
92 * Revision 1.16 1999/06/02 08:30:15 wolff
93 * added/removed the workaround for the DCD bug in the Firmware.
94 * A bit more debugging code to locate that...
96 * Revision 1.15 1999/06/01 11:35:30 wolff
97 * when DCD is left low (floating?), on TA's the firmware first tells us
98 * that DCD is high, but after a short while suddenly comes to the
99 * conclusion that it is low. All this would be fine, if it weren't that
100 * Unix requires us to send a "hangup" signal in that case. This usually
101 * all happens BEFORE the program has had a chance to ioctl the device
104 * Revision 1.14 1999/05/25 11:18:59 wolff
106 * Added checks for return code of sx_sendcommand.
107 * Don't issue "reconfig" if port isn't open yet. (bit us on TA modules...)
109 * Revision 1.13 1999/04/29 15:18:01 wolff
110 * Fixed an "oops" that showed on SuSE 6.0 systems.
111 * Activate DTR again after stty 0.
113 * Revision 1.12 1999/04/29 07:49:52 wolff
114 * Improved "stty 0" handling a bit. (used to change baud to 9600 assuming
115 * the connection would be dropped anyway. That is not always the case,
116 * and confuses people).
117 * Told the card to always monitor the modem signals.
118 * Added support for dynamic gs_debug adjustments.
119 * Now tells the rest of the system the number of ports.
121 * Revision 1.11 1999/04/24 11:11:30 wolff
122 * Fixed two stupid typos in the memory test.
124 * Revision 1.10 1999/04/24 10:53:39 wolff
125 * Added some of Christian's suggestions.
126 * Fixed an HW_COOK_IN bug (ISIG was not in I_OTHER. We used to trust the
127 * card to send the signal to the process.....)
129 * Revision 1.9 1999/04/23 07:26:38 wolff
130 * Included Christian Lademann's 2.0 compile-warning fixes and interrupt
131 * assignment redesign.
132 * Cleanup of some other stuff.
134 * Revision 1.8 1999/04/16 13:05:30 wolff
135 * fixed a DCD change unnoticed bug.
137 * Revision 1.7 1999/04/14 22:19:51 wolff
138 * Fixed typo that showed up in 2.0.x builds (get_user instead of Get_user!)
140 * Revision 1.6 1999/04/13 18:40:20 wolff
141 * changed misc-minor to 161, as assigned by HPA.
143 * Revision 1.5 1999/04/13 15:12:25 wolff
144 * Fixed use-count leak when "hangup" occurred.
145 * Added workaround for a stupid-PCIBIOS bug.
148 * Revision 1.4 1999/04/01 22:47:40 wolff
149 * Fixed < 1M linux-2.0 problem.
150 * (vremap isn't compatible with ioremap in that case)
152 * Revision 1.3 1999/03/31 13:45:45 wolff
153 * Firmware loading is now done through a separate IOCTL.
155 * Revision 1.2 1999/03/28 12:22:29 wolff
158 * Revision 1.1 1999/03/28 12:10:34 wolff
159 * Readying for release on 2.0.x (sorry David, 1.01 becomes 1.1 for RCS).
161 * Revision 0.12 1999/03/28 09:20:10 wolff
162 * Fixed problem in 0.11, continueing cleanup.
164 * Revision 0.11 1999/03/28 08:46:44 wolff
167 * Revision 0.10 1999/03/28 08:09:43 wolff
168 * Fixed loosing characters on close.
170 * Revision 0.9 1999/03/21 22:52:01 wolff
171 * Ported back to 2.2.... (minor things)
173 * Revision 0.8 1999/03/21 22:40:33 wolff
176 * Revision 0.7 1999/03/21 19:06:34 wolff
177 * Fixed hangup processing.
179 * Revision 0.6 1999/02/05 08:45:14 wolff
180 * fixed real_raw problems. Inclusion into kernel imminent.
182 * Revision 0.5 1998/12/21 23:51:06 wolff
183 * Snatched a nasty bug: sx_transmit_chars was getting re-entered, and it
184 * shouldn't have. THATs why I want to have transmit interrupts even when
185 * the buffer is empty.
187 * Revision 0.4 1998/12/17 09:34:46 wolff
188 * PPP works. ioctl works. Basically works!
190 * Revision 0.3 1998/12/15 13:05:18 wolff
191 * It works! Wow! Gotta start implementing IOCTL and stuff....
193 * Revision 0.2 1998/12/01 08:33:53 wolff
194 * moved over to 2.1.130
196 * Revision 0.1 1998/11/03 21:23:51 wolff
197 * Initial revision. Detects SX card.
201 #define SX_VERSION 1.33
203 #include <linux/module.h>
204 #include <linux/kdev_t.h>
205 #include <linux/kernel.h>
206 #include <linux/sched.h>
207 #include <linux/ioport.h>
208 #include <linux/interrupt.h>
209 #include <linux/errno.h>
210 #include <linux/tty.h>
211 #include <linux/tty_flip.h>
212 #include <linux/mm.h>
213 #include <linux/serial.h>
214 #include <linux/fcntl.h>
215 #include <linux/major.h>
216 #include <linux/delay.h>
217 #include <linux/pci.h>
218 #include <linux/slab.h>
219 #include <linux/init.h>
220 #include <linux/miscdevice.h>
221 #include <linux/bitops.h>
224 #include <asm/uaccess.h>
226 /* The 3.0.0 version of sxboards/sxwindow.h uses BYTE and WORD.... */
230 /* .... but the 3.0.4 version uses _u8 and _u16. */
234 #include "sxboards.h"
235 #include "sxwindow.h"
237 #include <linux/generic_serial.h>
241 /* I don't think that this driver can handle more than 256 ports on
242 one machine. You'll have to increase the number of boards in sx.h
243 if you want more than 4 boards. */
245 #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
246 #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
249 /* Configurable options:
250 (Don't be too sure that it'll work if you toggle them) */
252 /* Am I paranoid or not ? ;-) */
253 #undef SX_PARANOIA_CHECK
256 /* 20 -> 2000 per second. The card should rate-limit interrupts at 100
257 Hz, but it is user configurable. I don't recommend going above 1000
258 Hz. The interrupt ratelimit might trigger if the interrupt is
259 shared with a very active other device. */
260 #define IRQ_RATE_LIMIT 20
262 /* Sharing interrupts is possible now. If the other device wants more
263 than 2000 interrupts per second, we'd gracefully decline further
264 interrupts. That's not what we want. On the other hand, if the
265 other device interrupts 2000 times a second, don't use the SX
266 interrupt. Use polling. */
267 #undef IRQ_RATE_LIMIT
271 /* Not implemented */
273 * The following defines are mostly for testing purposes. But if you need
274 * some nice reporting in your syslog, you can define them also.
276 #define SX_REPORT_FIFO
277 #define SX_REPORT_OVERRUN
281 /* Function prototypes */
282 static void sx_disable_tx_interrupts (void * ptr);
283 static void sx_enable_tx_interrupts (void * ptr);
284 static void sx_disable_rx_interrupts (void * ptr);
285 static void sx_enable_rx_interrupts (void * ptr);
286 static int sx_get_CD (void * ptr);
287 static void sx_shutdown_port (void * ptr);
288 static int sx_set_real_termios (void *ptr);
289 static void sx_close (void *ptr);
290 static int sx_chars_in_buffer (void * ptr);
291 static int sx_init_board (struct sx_board *board);
292 static int sx_init_portstructs (int nboards, int nports);
293 static int sx_fw_ioctl (struct inode *inode, struct file *filp,
294 unsigned int cmd, unsigned long arg);
295 static int sx_init_drivers(void);
298 static struct tty_driver *sx_driver;
300 static struct sx_board boards[SX_NBOARDS];
301 static struct sx_port *sx_ports;
302 static int sx_initialized;
303 static int sx_nports;
307 /* You can have the driver poll your card.
308 - Set sx_poll to 1 to poll every timer tick (10ms on Intel).
309 This is used when the card cannot use an interrupt for some reason.
311 - set sx_slowpoll to 100 to do an extra poll once a second (on Intel). If
312 the driver misses an interrupt (report this if it DOES happen to you!)
313 everything will continue to work....
315 static int sx_poll = 1;
316 static int sx_slowpoll;
318 /* The card limits the number of interrupts per second.
319 At 115k2 "100" should be sufficient.
320 If you're using higher baudrates, you can increase this...
323 static int sx_maxints = 100;
325 /* These are the only open spaces in my computer. Yours may have more
327 duh: Card at 0xa0000 is possible on HP Netserver?? -- pvdl
329 static int sx_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000,
330 0xc8000, 0xd8000, 0xe8000};
331 static int si_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000,
332 0xc8000, 0xd8000, 0xe8000, 0xa0000};
333 static int si1_probe_addrs[]= { 0xd0000};
335 #define NR_SX_ADDRS ARRAY_SIZE(sx_probe_addrs)
336 #define NR_SI_ADDRS ARRAY_SIZE(si_probe_addrs)
337 #define NR_SI1_ADDRS ARRAY_SIZE(si1_probe_addrs)
340 /* Set the mask to all-ones. This alas, only supports 32 interrupts.
341 Some architectures may need more. */
342 static int sx_irqmask = -1;
344 module_param_array(sx_probe_addrs, int, NULL, 0);
345 module_param_array(si_probe_addrs, int, NULL, 0);
346 module_param(sx_poll, int, 0);
347 module_param(sx_slowpoll, int, 0);
348 module_param(sx_maxints, int, 0);
349 module_param(sx_debug, int, 0);
350 module_param(sx_irqmask, int, 0);
352 MODULE_LICENSE("GPL");
354 static struct real_driver sx_real_driver = {
355 sx_disable_tx_interrupts,
356 sx_enable_tx_interrupts,
357 sx_disable_rx_interrupts,
358 sx_enable_rx_interrupts,
368 This driver can spew a whole lot of debugging output at you. If you
369 need maximum performance, you should disable the DEBUG define. To
370 aid in debugging in the field, I'm leaving the compile-time debug
371 features enabled, and disable them "runtime". That allows me to
372 instruct people with problems to enable debugging without requiring
379 #define sx_dprintk(f, str...) if (sx_debug & f) printk (str)
381 #define sx_dprintk(f, str...) /* nothing */
386 #define func_enter() sx_dprintk (SX_DEBUG_FLOW, "sx: enter %s\n",__FUNCTION__)
387 #define func_exit() sx_dprintk (SX_DEBUG_FLOW, "sx: exit %s\n", __FUNCTION__)
389 #define func_enter2() sx_dprintk (SX_DEBUG_FLOW, "sx: enter %s (port %d)\n", \
390 __FUNCTION__, port->line)
396 * Firmware loader driver specific routines
400 static const struct file_operations sx_fw_fops = {
401 .owner = THIS_MODULE,
402 .ioctl = sx_fw_ioctl,
405 static struct miscdevice sx_fw_device = {
406 SXCTL_MISC_MINOR, "sxctl", &sx_fw_fops
413 #ifdef SX_PARANOIA_CHECK
415 /* This doesn't work. Who's paranoid around here? Not me! */
417 static inline int sx_paranoia_check(struct sx_port const * port,
418 char *name, const char *routine)
421 static const char *badmagic =
422 KERN_ERR "sx: Warning: bad sx port magic number for device %s in %s\n";
423 static const char *badinfo =
424 KERN_ERR "sx: Warning: null sx port for device %s in %s\n";
427 printk(badinfo, name, routine);
430 if (port->magic != SX_MAGIC) {
431 printk(badmagic, name, routine);
438 #define sx_paranoia_check(a,b,c) 0
441 /* The timeouts. First try 30 times as fast as possible. Then give
442 the card some time to breathe between accesses. (Otherwise the
443 processor on the card might not be able to access its OWN bus... */
446 #define TIMEOUT_2 1000000
450 static void my_hd_io(void __iomem *p, int len)
453 unsigned char __iomem *addr = p;
455 for (i=0;i<len;i+=16) {
456 printk ("%p ", addr+i);
458 printk ("%02x %s", readb(addr+j+i), (j==7)?" ":"");
461 ch = readb(addr+j+i);
462 printk ("%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
467 static void my_hd(void *p, int len)
470 unsigned char *addr = p;
472 for (i=0;i<len;i+=16) {
473 printk ("%p ", addr+i);
475 printk ("%02x %s", addr[j+i], (j==7)?" ":"");
479 printk ("%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
488 /* This needs redoing for Alpha -- REW -- Done. */
490 static inline void write_sx_byte (struct sx_board *board, int offset, u8 byte)
492 writeb (byte, board->base+offset);
495 static inline u8 read_sx_byte (struct sx_board *board, int offset)
497 return readb (board->base+offset);
501 static inline void write_sx_word (struct sx_board *board, int offset, u16 word)
503 writew (word, board->base+offset);
506 static inline u16 read_sx_word (struct sx_board *board, int offset)
508 return readw (board->base + offset);
512 static int sx_busy_wait_eq (struct sx_board *board,
513 int offset, int mask, int correctval)
519 for (i=0; i < TIMEOUT_1 ;i++)
520 if ((read_sx_byte (board, offset) & mask) == correctval) {
525 for (i=0; i < TIMEOUT_2 ;i++) {
526 if ((read_sx_byte (board, offset) & mask) == correctval) {
538 static int sx_busy_wait_neq (struct sx_board *board,
539 int offset, int mask, int badval)
545 for (i=0; i < TIMEOUT_1 ;i++)
546 if ((read_sx_byte (board, offset) & mask) != badval) {
551 for (i=0; i < TIMEOUT_2 ;i++) {
552 if ((read_sx_byte (board, offset) & mask) != badval) {
565 /* 5.6.4 of 6210028 r2.3 */
566 static int sx_reset (struct sx_board *board)
570 if (IS_SX_BOARD (board)) {
572 write_sx_byte (board, SX_CONFIG, 0);
573 write_sx_byte (board, SX_RESET, 1); /* Value doesn't matter */
575 if (!sx_busy_wait_eq (board, SX_RESET_STATUS, 1, 0)) {
576 printk (KERN_INFO "sx: Card doesn't respond to reset....\n");
579 } else if (IS_EISA_BOARD(board)) {
580 outb(board->irq<<4, board->eisa_base+0xc02);
581 } else if (IS_SI1_BOARD(board)) {
582 write_sx_byte (board, SI1_ISA_RESET, 0); // value does not matter
584 /* Gory details of the SI/ISA board */
585 write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_SET);
586 write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_CLEAR);
587 write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_CLEAR);
588 write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_CLEAR);
589 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR);
590 write_sx_byte (board, SI2_ISA_IRQSET, SI2_ISA_IRQSET_CLEAR);
598 /* This doesn't work on machines where "NULL" isn't 0 */
599 /* If you have one of those, someone will need to write
600 the equivalent of this, which will amount to about 3 lines. I don't
601 want to complicate this right now. -- REW
602 (See, I do write comments every now and then :-) */
603 #define OFFSETOF(strct, elem) ((long)&(((struct strct *)NULL)->elem))
606 #define CHAN_OFFSET(port,elem) (port->ch_base + OFFSETOF (_SXCHANNEL, elem))
607 #define MODU_OFFSET(board,addr,elem) (addr + OFFSETOF (_SXMODULE, elem))
608 #define BRD_OFFSET(board,elem) (OFFSETOF (_SXCARD, elem))
611 #define sx_write_channel_byte(port, elem, val) \
612 write_sx_byte (port->board, CHAN_OFFSET (port, elem), val)
614 #define sx_read_channel_byte(port, elem) \
615 read_sx_byte (port->board, CHAN_OFFSET (port, elem))
617 #define sx_write_channel_word(port, elem, val) \
618 write_sx_word (port->board, CHAN_OFFSET (port, elem), val)
620 #define sx_read_channel_word(port, elem) \
621 read_sx_word (port->board, CHAN_OFFSET (port, elem))
624 #define sx_write_module_byte(board, addr, elem, val) \
625 write_sx_byte (board, MODU_OFFSET (board, addr, elem), val)
627 #define sx_read_module_byte(board, addr, elem) \
628 read_sx_byte (board, MODU_OFFSET (board, addr, elem))
630 #define sx_write_module_word(board, addr, elem, val) \
631 write_sx_word (board, MODU_OFFSET (board, addr, elem), val)
633 #define sx_read_module_word(board, addr, elem) \
634 read_sx_word (board, MODU_OFFSET (board, addr, elem))
637 #define sx_write_board_byte(board, elem, val) \
638 write_sx_byte (board, BRD_OFFSET (board, elem), val)
640 #define sx_read_board_byte(board, elem) \
641 read_sx_byte (board, BRD_OFFSET (board, elem))
643 #define sx_write_board_word(board, elem, val) \
644 write_sx_word (board, BRD_OFFSET (board, elem), val)
646 #define sx_read_board_word(board, elem) \
647 read_sx_word (board, BRD_OFFSET (board, elem))
650 static int sx_start_board (struct sx_board *board)
652 if (IS_SX_BOARD (board)) {
653 write_sx_byte (board, SX_CONFIG, SX_CONF_BUSEN);
654 } else if (IS_EISA_BOARD(board)) {
655 write_sx_byte(board, SI2_EISA_OFF, SI2_EISA_VAL);
656 outb((board->irq<<4)|4, board->eisa_base+0xc02);
657 } else if (IS_SI1_BOARD(board)) {
658 write_sx_byte (board, SI1_ISA_RESET_CLEAR, 0);
659 write_sx_byte (board, SI1_ISA_INTCL, 0);
661 /* Don't bug me about the clear_set.
662 I haven't the foggiest idea what it's about -- REW */
663 write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_CLEAR);
664 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
669 #define SX_IRQ_REG_VAL(board) \
670 ((board->flags & SX_ISA_BOARD)?(board->irq << 4):0)
672 /* Note. The SX register is write-only. Therefore, we have to enable the
673 bus too. This is a no-op, if you don't mess with this driver... */
674 static int sx_start_interrupts (struct sx_board *board)
677 /* Don't call this with board->irq == 0 */
679 if (IS_SX_BOARD(board)) {
680 write_sx_byte (board, SX_CONFIG, SX_IRQ_REG_VAL (board) |
683 } else if (IS_EISA_BOARD(board)) {
684 inb(board->eisa_base+0xc03);
685 } else if (IS_SI1_BOARD(board)) {
686 write_sx_byte (board, SI1_ISA_INTCL,0);
687 write_sx_byte (board, SI1_ISA_INTCL_CLEAR,0);
689 switch (board->irq) {
690 case 11:write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_SET);break;
691 case 12:write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_SET);break;
692 case 15:write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_SET);break;
693 default:printk (KERN_INFO "sx: SI/XIO card doesn't support interrupt %d.\n",
697 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
704 static int sx_send_command (struct sx_port *port,
705 int command, int mask, int newstat)
708 write_sx_byte (port->board, CHAN_OFFSET (port, hi_hstat), command);
710 return sx_busy_wait_eq (port->board, CHAN_OFFSET (port, hi_hstat), mask, newstat);
714 static char *mod_type_s (int module_type)
716 switch (module_type) {
717 case TA4: return "TA4";
718 case TA8: return "TA8";
719 case TA4_ASIC: return "TA4_ASIC";
720 case TA8_ASIC: return "TA8_ASIC";
721 case MTA_CD1400:return "MTA_CD1400";
722 case SXDC: return "SXDC";
723 default:return "Unknown/invalid";
728 static char *pan_type_s (int pan_type)
731 case MOD_RS232DB25: return "MOD_RS232DB25";
732 case MOD_RS232RJ45: return "MOD_RS232RJ45";
733 case MOD_RS422DB25: return "MOD_RS422DB25";
734 case MOD_PARALLEL: return "MOD_PARALLEL";
735 case MOD_2_RS232DB25: return "MOD_2_RS232DB25";
736 case MOD_2_RS232RJ45: return "MOD_2_RS232RJ45";
737 case MOD_2_RS422DB25: return "MOD_2_RS422DB25";
738 case MOD_RS232DB25MALE: return "MOD_RS232DB25MALE";
739 case MOD_2_PARALLEL: return "MOD_2_PARALLEL";
740 case MOD_BLANK: return "empty";
741 default:return "invalid";
746 static int mod_compat_type (int module_type)
748 return module_type >> 4;
751 static void sx_reconfigure_port(struct sx_port *port)
753 if (sx_read_channel_byte (port, hi_hstat) == HS_IDLE_OPEN) {
754 if (sx_send_command (port, HS_CONFIG, -1, HS_IDLE_OPEN) != 1) {
755 printk (KERN_WARNING "sx: Sent reconfigure command, but card didn't react.\n");
758 sx_dprintk (SX_DEBUG_TERMIOS,
759 "sx: Not sending reconfigure: port isn't open (%02x).\n",
760 sx_read_channel_byte (port, hi_hstat));
764 static void sx_setsignals (struct sx_port *port, int dtr, int rts)
769 t = sx_read_channel_byte (port, hi_op);
770 if (dtr >= 0) t = dtr? (t | OP_DTR): (t & ~OP_DTR);
771 if (rts >= 0) t = rts? (t | OP_RTS): (t & ~OP_RTS);
772 sx_write_channel_byte (port, hi_op, t);
773 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "setsignals: %d/%d\n", dtr, rts);
780 static int sx_getsignals (struct sx_port *port)
784 o_stat = sx_read_channel_byte (port, hi_op);
785 i_stat = sx_read_channel_byte (port, hi_ip);
787 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) %02x/%02x\n",
788 (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0,
789 port->c_dcd, sx_get_CD (port),
790 sx_read_channel_byte (port, hi_ip),
791 sx_read_channel_byte (port, hi_state));
793 return (((o_stat & OP_DTR)?TIOCM_DTR:0) |
794 ((o_stat & OP_RTS)?TIOCM_RTS:0) |
795 ((i_stat & IP_CTS)?TIOCM_CTS:0) |
796 ((i_stat & IP_DCD)?TIOCM_CAR:0) |
797 ((i_stat & IP_DSR)?TIOCM_DSR:0) |
798 ((i_stat & IP_RI)?TIOCM_RNG:0)
803 static void sx_set_baud (struct sx_port *port)
807 if (port->board->ta_type == MOD_SXDC) {
808 switch (port->gs.baud) {
809 /* Save some typing work... */
810 #define e(x) case x:t= BAUD_ ## x ; break
811 e(50);e(75);e(110);e(150);e(200);e(300);e(600);
812 e(1200);e(1800);e(2000);e(2400);e(4800);e(7200);
813 e(9600);e(14400);e(19200);e(28800);e(38400);
814 e(56000);e(57600);e(64000);e(76800);e(115200);
815 e(128000);e(150000);e(230400);e(256000);e(460800);
817 case 134 :t = BAUD_134_5; break;
821 /* Can I return "invalid"? */
823 printk (KERN_INFO "sx: unsupported baud rate: %d.\n", port->gs.baud);
828 /* The baud rate is not set to 0, so we're enabeling DTR... -- REW */
829 sx_setsignals (port, 1, -1);
830 /* XXX This is not TA & MTA compatible */
831 sx_write_channel_byte (port, hi_csr, 0xff);
833 sx_write_channel_byte (port, hi_txbaud, t);
834 sx_write_channel_byte (port, hi_rxbaud, t);
836 sx_setsignals (port, 0, -1);
839 switch (port->gs.baud) {
840 #define e(x) case x:t= CSR_ ## x ; break
841 e(75);e(150);e(300);e(600);e(1200);e(2400);e(4800);
843 e(19200);e(57600);e(38400);
844 /* TA supports 110, but not 115200, MTA supports 115200, but not 110 */
846 if (port->board->ta_type == MOD_TA) {
851 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
855 if (port->board->ta_type == MOD_TA) {
857 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
867 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
872 sx_setsignals (port, 1, -1);
873 sx_write_channel_byte (port, hi_csr, t * 0x11);
875 sx_setsignals (port, 0, -1);
881 /* Simon Allen's version of this routine was 225 lines long. 85 is a lot
884 static int sx_set_real_termios (void *ptr)
886 struct sx_port *port = ptr;
893 /* What is this doing here? -- REW
894 Ha! figured it out. It is to allow you to get DTR active again
895 if you've dropped it with stty 0. Moved to set_baud, where it
896 belongs (next to the drop dtr if baud == 0) -- REW */
897 /* sx_setsignals (port, 1, -1); */
901 #define CFLAG port->gs.tty->termios->c_cflag
902 sx_write_channel_byte (port, hi_mr1,
903 (C_PARENB (port->gs.tty)? MR1_WITH:MR1_NONE) |
904 (C_PARODD (port->gs.tty)? MR1_ODD:MR1_EVEN) |
905 (C_CRTSCTS(port->gs.tty)? MR1_RTS_RXFLOW:0) |
906 (((CFLAG & CSIZE)==CS8) ? MR1_8_BITS:0) |
907 (((CFLAG & CSIZE)==CS7) ? MR1_7_BITS:0) |
908 (((CFLAG & CSIZE)==CS6) ? MR1_6_BITS:0) |
909 (((CFLAG & CSIZE)==CS5) ? MR1_5_BITS:0) );
911 sx_write_channel_byte (port, hi_mr2,
912 (C_CRTSCTS(port->gs.tty)?MR2_CTS_TXFLOW:0) |
913 (C_CSTOPB (port->gs.tty)?MR2_2_STOP:MR2_1_STOP));
915 switch (CFLAG & CSIZE) {
916 case CS8:sx_write_channel_byte (port, hi_mask, 0xff);break;
917 case CS7:sx_write_channel_byte (port, hi_mask, 0x7f);break;
918 case CS6:sx_write_channel_byte (port, hi_mask, 0x3f);break;
919 case CS5:sx_write_channel_byte (port, hi_mask, 0x1f);break;
921 printk (KERN_INFO "sx: Invalid wordsize: %u\n", CFLAG & CSIZE);
925 sx_write_channel_byte (port, hi_prtcl,
926 (I_IXON (port->gs.tty)?SP_TXEN:0) |
927 (I_IXOFF (port->gs.tty)?SP_RXEN:0) |
928 (I_IXANY (port->gs.tty)?SP_TANY:0) |
931 sx_write_channel_byte (port, hi_break,
932 (I_IGNBRK(port->gs.tty)?BR_IGN:0 |
933 I_BRKINT(port->gs.tty)?BR_INT:0));
935 sx_write_channel_byte (port, hi_txon, START_CHAR (port->gs.tty));
936 sx_write_channel_byte (port, hi_rxon, START_CHAR (port->gs.tty));
937 sx_write_channel_byte (port, hi_txoff, STOP_CHAR (port->gs.tty));
938 sx_write_channel_byte (port, hi_rxoff, STOP_CHAR (port->gs.tty));
940 sx_reconfigure_port(port);
942 /* Tell line discipline whether we will do input cooking */
943 if(I_OTHER(port->gs.tty)) {
944 clear_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
946 set_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
948 sx_dprintk (SX_DEBUG_TERMIOS, "iflags: %x(%d) ",
949 port->gs.tty->termios->c_iflag,
950 I_OTHER(port->gs.tty));
953 /* Tell line discipline whether we will do output cooking.
954 * If OPOST is set and no other output flags are set then we can do output
955 * processing. Even if only *one* other flag in the O_OTHER group is set
956 * we do cooking in software.
958 if(O_OPOST(port->gs.tty) && !O_OTHER(port->gs.tty)) {
959 set_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
961 clear_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
963 sx_dprintk (SX_DEBUG_TERMIOS, "oflags: %x(%d)\n",
964 port->gs.tty->termios->c_oflag,
965 O_OTHER(port->gs.tty));
966 /* port->c_dcd = sx_get_CD (port); */
973 /* ********************************************************************** *
974 * the interrupt related routines *
975 * ********************************************************************** */
978 Other drivers use the macro "MIN" to calculate how much to copy.
979 This has the disadvantage that it will evaluate parts twice. That's
980 expensive when it's IO (and the compiler cannot optimize those away!).
981 Moreover, I'm not sure that you're race-free.
983 I assign a value, and then only allow the value to decrease. This
984 is always safe. This makes the code a few lines longer, and you
985 know I'm dead against that, but I think it is required in this
989 static void sx_transmit_chars (struct sx_port *port)
996 sx_dprintk (SX_DEBUG_TRANSMIT, "Port %p: transmit %d chars\n",
997 port, port->gs.xmit_cnt);
999 if (test_and_set_bit (SX_PORT_TRANSMIT_LOCK, &port->locks)) {
1004 c = port->gs.xmit_cnt;
1006 sx_dprintk (SX_DEBUG_TRANSMIT, "Copying %d ", c);
1007 tx_ip = sx_read_channel_byte (port, hi_txipos);
1009 /* Took me 5 minutes to deduce this formula.
1010 Luckily it is literally in the manual in section 6.5.4.3.5 */
1011 txroom = (sx_read_channel_byte (port, hi_txopos) - tx_ip - 1) & 0xff;
1013 /* Don't copy more bytes than there is room for in the buffer */
1016 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, txroom );
1018 /* Don't copy past the end of the hardware transmit buffer */
1019 if (c > 0x100 - tx_ip)
1022 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, 0x100-tx_ip );
1024 /* Don't copy pas the end of the source buffer */
1025 if (c > SERIAL_XMIT_SIZE - port->gs.xmit_tail)
1026 c = SERIAL_XMIT_SIZE - port->gs.xmit_tail;
1028 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%ld) \n",
1029 c, SERIAL_XMIT_SIZE- port->gs.xmit_tail);
1031 /* If for one reason or another, we can't copy more data, we're done! */
1035 memcpy_toio (port->board->base + CHAN_OFFSET(port,hi_txbuf) + tx_ip,
1036 port->gs.xmit_buf + port->gs.xmit_tail, c);
1038 /* Update the pointer in the card */
1039 sx_write_channel_byte (port, hi_txipos, (tx_ip+c) & 0xff);
1041 /* Update the kernel buffer end */
1042 port->gs.xmit_tail = (port->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE-1);
1044 /* This one last. (this is essential)
1045 It would allow others to start putting more data into the buffer! */
1046 port->gs.xmit_cnt -= c;
1049 if (port->gs.xmit_cnt == 0) {
1050 sx_disable_tx_interrupts (port);
1053 if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.tty) {
1054 tty_wakeup(port->gs.tty);
1055 sx_dprintk (SX_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n",
1056 port->gs.wakeup_chars);
1059 clear_bit (SX_PORT_TRANSMIT_LOCK, &port->locks);
1064 /* Note the symmetry between receiving chars and transmitting them!
1065 Note: The kernel should have implemented both a receive buffer and
1066 a transmit buffer. */
1068 /* Inlined: Called only once. Remove the inline when you add another call */
1069 static inline void sx_receive_chars (struct sx_port *port)
1073 struct tty_struct *tty;
1080 rx_op = sx_read_channel_byte (port, hi_rxopos);
1081 c = (sx_read_channel_byte (port, hi_rxipos) - rx_op) & 0xff;
1083 sx_dprintk (SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c);
1085 /* Don't copy past the end of the hardware receive buffer */
1086 if (rx_op + c > 0x100) c = 0x100 - rx_op;
1088 sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
1090 /* Don't copy more bytes than there is room for in the buffer */
1092 c = tty_prepare_flip_string(tty, &rp, c);
1094 sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
1096 /* If for one reason or another, we can't copy more data, we're done! */
1099 sx_dprintk (SX_DEBUG_RECEIVE , "Copying over %d chars. First is %d at %lx\n", c,
1100 read_sx_byte (port->board, CHAN_OFFSET(port,hi_rxbuf) + rx_op),
1101 CHAN_OFFSET(port, hi_rxbuf));
1103 port->board->base + CHAN_OFFSET(port,hi_rxbuf) + rx_op, c);
1105 /* This one last. ( Not essential.)
1106 It allows the card to start putting more data into the buffer!
1107 Update the pointer in the card */
1108 sx_write_channel_byte (port, hi_rxopos, (rx_op + c) & 0xff);
1115 do_gettimeofday (&tv);
1116 sx_dprintk (SX_DEBUG_RECEIVE,
1117 "pushing flipq port %d (%3d chars): %d.%06d (%d/%d)\n",
1119 (int) (tv.tv_sec % 60), (int)tv.tv_usec, tty->raw, tty->real_raw);
1121 /* Tell the rest of the system the news. Great news. New characters! */
1122 tty_flip_buffer_push (tty);
1123 /* tty_schedule_flip (tty); */
1129 /* Inlined: it is called only once. Remove the inline if you add another
1131 static inline void sx_check_modem_signals (struct sx_port *port)
1136 hi_state = sx_read_channel_byte (port, hi_state);
1137 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n",
1138 port->c_dcd, sx_get_CD (port));
1140 if (hi_state & ST_BREAK) {
1141 hi_state &= ~ST_BREAK;
1142 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a break.\n");
1143 sx_write_channel_byte (port, hi_state, hi_state);
1144 gs_got_break (&port->gs);
1146 if (hi_state & ST_DCD) {
1147 hi_state &= ~ST_DCD;
1148 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n");
1149 sx_write_channel_byte (port, hi_state, hi_state);
1150 c_dcd = sx_get_CD (port);
1151 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd);
1152 if (c_dcd != port->c_dcd) {
1153 port->c_dcd = c_dcd;
1154 if (sx_get_CD (port)) {
1156 if ((sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED) &&
1157 !(port->gs.tty->termios->c_cflag & CLOCAL) ) {
1158 /* Are we blocking in open?*/
1159 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD active, unblocking open\n");
1160 wake_up_interruptible(&port->gs.open_wait);
1162 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD raised. Ignoring.\n");
1165 /* DCD went down! */
1166 if (!(port->gs.tty->termios->c_cflag & CLOCAL) ) {
1167 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. hanging up....\n");
1168 tty_hangup (port->gs.tty);
1170 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. ignoring.\n");
1174 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Hmmm. card told us DCD changed, but it didn't.\n");
1180 /* This is what an interrupt routine should look like.
1181 * Small, elegant, clear.
1184 static irqreturn_t sx_interrupt (int irq, void *ptr)
1186 struct sx_board *board = ptr;
1187 struct sx_port *port;
1191 sx_dprintk (SX_DEBUG_FLOW, "sx: enter sx_interrupt (%d/%d)\n", irq, board->irq);
1193 /* AAargh! The order in which to do these things is essential and
1196 - Rate limit goes before "recursive". Otherwise a series of
1197 recursive calls will hang the machine in the interrupt routine.
1199 - hardware twiddling goes before "recursive". Otherwise when we
1200 poll the card, and a recursive interrupt happens, we won't
1201 ack the card, so it might keep on interrupting us. (especially
1202 level sensitive interrupt systems like PCI).
1204 - Rate limit goes before hardware twiddling. Otherwise we won't
1205 catch a card that has gone bonkers.
1207 - The "initialized" test goes after the hardware twiddling. Otherwise
1208 the card will stick us in the interrupt routine again.
1210 - The initialized test goes before recursive.
1215 #ifdef IRQ_RATE_LIMIT
1216 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
1217 actual interrupt routine!. (Well, used to when I wrote that comment) */
1222 if (lastjif == jiffies) {
1223 if (++nintr > IRQ_RATE_LIMIT) {
1224 free_irq (board->irq, board);
1225 printk (KERN_ERR "sx: Too many interrupts. Turning off interrupt %d.\n",
1236 if (board->irq == irq) {
1237 /* Tell the card we've noticed the interrupt. */
1239 sx_write_board_word (board, cc_int_pending, 0);
1240 if (IS_SX_BOARD (board)) {
1241 write_sx_byte (board, SX_RESET_IRQ, 1);
1242 } else if (IS_EISA_BOARD(board)) {
1243 inb(board->eisa_base+0xc03);
1244 write_sx_word(board, 8, 0);
1246 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR);
1247 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
1251 if (!sx_initialized)
1253 if (!(board->flags & SX_BOARD_INITIALIZED))
1256 if (test_and_set_bit (SX_BOARD_INTR_LOCK, &board->locks)) {
1257 printk (KERN_ERR "Recursive interrupt! (%d)\n", board->irq);
1261 for (i=0;i<board->nports;i++) {
1262 port = &board->ports[i];
1263 if (port->gs.flags & GS_ACTIVE) {
1264 if (sx_read_channel_byte (port, hi_state)) {
1265 sx_dprintk (SX_DEBUG_INTERRUPTS,
1266 "Port %d: modem signal change?... \n", i);
1267 sx_check_modem_signals (port);
1269 if (port->gs.xmit_cnt) {
1270 sx_transmit_chars (port);
1272 if (!(port->gs.flags & SX_RX_THROTTLE)) {
1273 sx_receive_chars (port);
1278 clear_bit (SX_BOARD_INTR_LOCK, &board->locks);
1280 sx_dprintk (SX_DEBUG_FLOW, "sx: exit sx_interrupt (%d/%d)\n", irq, board->irq);
1286 static void sx_pollfunc (unsigned long data)
1288 struct sx_board *board = (struct sx_board *) data;
1292 sx_interrupt (0, board);
1294 init_timer(&board->timer);
1296 board->timer.expires = jiffies + sx_poll;
1297 add_timer (&board->timer);
1303 /* ********************************************************************** *
1304 * Here are the routines that actually *
1305 * interface with the generic_serial driver *
1306 * ********************************************************************** */
1308 /* Ehhm. I don't know how to fiddle with interrupts on the SX card. --REW */
1309 /* Hmm. Ok I figured it out. You don't. */
1311 static void sx_disable_tx_interrupts (void * ptr)
1313 struct sx_port *port = ptr;
1316 port->gs.flags &= ~GS_TX_INTEN;
1322 static void sx_enable_tx_interrupts (void * ptr)
1324 struct sx_port *port = ptr;
1328 /* First transmit the characters that we're supposed to */
1329 sx_transmit_chars (port);
1331 /* The sx card will never interrupt us if we don't fill the buffer
1332 past 25%. So we keep considering interrupts off if that's the case. */
1333 data_in_buffer = (sx_read_channel_byte (port, hi_txipos) -
1334 sx_read_channel_byte (port, hi_txopos)) & 0xff;
1336 /* XXX Must be "HIGH_WATER" for SI card according to doc. */
1337 if (data_in_buffer < LOW_WATER)
1338 port->gs.flags &= ~GS_TX_INTEN;
1344 static void sx_disable_rx_interrupts (void * ptr)
1346 /* struct sx_port *port = ptr; */
1352 static void sx_enable_rx_interrupts (void * ptr)
1354 /* struct sx_port *port = ptr; */
1361 /* Jeez. Isn't this simple? */
1362 static int sx_get_CD (void * ptr)
1364 struct sx_port *port = ptr;
1368 return ((sx_read_channel_byte (port, hi_ip) & IP_DCD) != 0);
1372 /* Jeez. Isn't this simple? */
1373 static int sx_chars_in_buffer (void * ptr)
1375 struct sx_port *port = ptr;
1379 return ((sx_read_channel_byte (port, hi_txipos) -
1380 sx_read_channel_byte (port, hi_txopos)) & 0xff);
1384 static void sx_shutdown_port (void * ptr)
1386 struct sx_port *port = ptr;
1390 port->gs.flags &= ~ GS_ACTIVE;
1391 if (port->gs.tty && (port->gs.tty->termios->c_cflag & HUPCL)) {
1392 sx_setsignals (port, 0, 0);
1393 sx_reconfigure_port(port);
1403 /* ********************************************************************** *
1404 * Here are the routines that actually *
1405 * interface with the rest of the system *
1406 * ********************************************************************** */
1408 static int sx_open (struct tty_struct * tty, struct file * filp)
1410 struct sx_port *port;
1412 unsigned long flags;
1416 if (!sx_initialized) {
1421 sx_dprintk (SX_DEBUG_OPEN, "%d: opening line %d. tty=%p ctty=%p, np=%d)\n",
1422 current->pid, line, tty, current->signal->tty, sx_nports);
1424 if ((line < 0) || (line >= SX_NPORTS) || (line >= sx_nports))
1427 port = & sx_ports[line];
1428 port->c_dcd = 0; /* Make sure that the first interrupt doesn't detect a
1429 1 -> 0 transition. */
1432 sx_dprintk (SX_DEBUG_OPEN, "port = %p c_dcd = %d\n", port, port->c_dcd);
1434 spin_lock_irqsave(&port->gs.driver_lock, flags);
1436 tty->driver_data = port;
1439 spin_unlock_irqrestore(&port->gs.driver_lock, flags);
1441 sx_dprintk (SX_DEBUG_OPEN, "starting port\n");
1444 * Start up serial port
1446 retval = gs_init_port(&port->gs);
1447 sx_dprintk (SX_DEBUG_OPEN, "done gs_init\n");
1453 port->gs.flags |= GS_ACTIVE;
1454 if (port->gs.count <= 1)
1455 sx_setsignals (port, 1,1);
1458 if (sx_debug & SX_DEBUG_OPEN)
1459 my_hd (port, sizeof (*port));
1461 if (sx_debug & SX_DEBUG_OPEN)
1462 my_hd_io (port->board->base + port->ch_base, sizeof (*port));
1465 if (port->gs.count <= 1) {
1466 if (sx_send_command (port, HS_LOPEN, -1, HS_IDLE_OPEN) != 1) {
1467 printk (KERN_ERR "sx: Card didn't respond to LOPEN command.\n");
1468 spin_lock_irqsave(&port->gs.driver_lock, flags);
1470 spin_unlock_irqrestore(&port->gs.driver_lock, flags);
1475 retval = gs_block_til_ready(port, filp);
1476 sx_dprintk (SX_DEBUG_OPEN, "Block til ready returned %d. Count=%d\n",
1477 retval, port->gs.count);
1481 * Don't lower gs.count here because sx_close() will be called later
1486 /* tty->low_latency = 1; */
1488 port->c_dcd = sx_get_CD (port);
1489 sx_dprintk (SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd);
1497 static void sx_close (void *ptr)
1499 struct sx_port *port = ptr;
1500 /* Give the port 5 seconds to close down. */
1505 sx_setsignals (port, 0, 0);
1506 sx_reconfigure_port(port);
1507 sx_send_command (port, HS_CLOSE, 0, 0);
1509 while (to-- && (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED))
1510 if (msleep_interruptible(10))
1512 if (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED) {
1513 if (sx_send_command (port, HS_FORCE_CLOSED, -1, HS_IDLE_CLOSED) != 1) {
1515 "sx: sent the force_close command, but card didn't react\n");
1517 sx_dprintk (SX_DEBUG_CLOSE, "sent the force_close command.\n");
1520 sx_dprintk (SX_DEBUG_CLOSE, "waited %d jiffies for close. count=%d\n",
1521 5 * HZ - to - 1, port->gs.count);
1523 if(port->gs.count) {
1524 sx_dprintk(SX_DEBUG_CLOSE, "WARNING port count:%d\n", port->gs.count);
1525 //printk ("%s SETTING port count to zero: %p count: %d\n", __FUNCTION__, port, port->gs.count);
1526 //port->gs.count = 0;
1534 /* This is relatively thorough. But then again it is only 20 lines. */
1535 #define MARCHUP for (i=min;i<max;i++)
1536 #define MARCHDOWN for (i=max-1;i>=min;i--)
1537 #define W0 write_sx_byte (board, i, 0x55)
1538 #define W1 write_sx_byte (board, i, 0xaa)
1539 #define R0 if (read_sx_byte (board, i) != 0x55) return 1
1540 #define R1 if (read_sx_byte (board, i) != 0xaa) return 1
1542 /* This memtest takes a human-noticable time. You normally only do it
1543 once a boot, so I guess that it is worth it. */
1544 static int do_memtest (struct sx_board *board, int min, int max)
1548 /* This is a marchb. Theoretically, marchb catches much more than
1549 simpler tests. In practise, the longer test just catches more
1550 intermittent errors. -- REW
1551 (For the theory behind memory testing see:
1552 Testing Semiconductor Memories by A.J. van de Goor.) */
1554 MARCHUP {R0;W1;R1;W0;R0;W1;}
1556 MARCHDOWN {R1;W0;W1;W0;}
1557 MARCHDOWN {R0;W1;W0;}
1570 #define MARCHUP for (i=min;i<max;i+=2)
1571 #define MARCHDOWN for (i=max-1;i>=min;i-=2)
1572 #define W0 write_sx_word (board, i, 0x55aa)
1573 #define W1 write_sx_word (board, i, 0xaa55)
1574 #define R0 if (read_sx_word (board, i) != 0x55aa) return 1
1575 #define R1 if (read_sx_word (board, i) != 0xaa55) return 1
1578 /* This memtest takes a human-noticable time. You normally only do it
1579 once a boot, so I guess that it is worth it. */
1580 static int do_memtest_w (struct sx_board *board, int min, int max)
1585 MARCHUP {R0;W1;R1;W0;R0;W1;}
1587 MARCHDOWN {R1;W0;W1;W0;}
1588 MARCHDOWN {R0;W1;W0;}
1595 static int sx_fw_ioctl (struct inode *inode, struct file *filp,
1596 unsigned int cmd, unsigned long arg)
1599 int __user *descr = (int __user *)arg;
1601 static struct sx_board *board = NULL;
1609 /* Removed superuser check: Sysops can use the permissions on the device
1610 file to restrict access. Recommendation: Root only. (root.root 600) */
1611 if (!capable(CAP_SYS_ADMIN)) {
1616 sx_dprintk (SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg);
1618 if (!board) board = &boards[0];
1619 if (board->flags & SX_BOARD_PRESENT) {
1620 sx_dprintk (SX_DEBUG_FIRMWARE, "Board present! (%x)\n",
1623 sx_dprintk (SX_DEBUG_FIRMWARE, "Board not present! (%x) all:",
1625 for (i=0;i< SX_NBOARDS;i++)
1626 sx_dprintk (SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags);
1627 sx_dprintk (SX_DEBUG_FIRMWARE, "\n");
1632 case SXIO_SET_BOARD:
1633 sx_dprintk (SX_DEBUG_FIRMWARE, "set board to %ld\n", arg);
1634 if (arg >= SX_NBOARDS) return -EIO;
1635 sx_dprintk (SX_DEBUG_FIRMWARE, "not out of range\n");
1636 if (!(boards[arg].flags & SX_BOARD_PRESENT)) return -EIO;
1637 sx_dprintk (SX_DEBUG_FIRMWARE, ".. and present!\n");
1638 board = &boards[arg];
1641 rc = -ENOENT; /* If we manage to miss one, return error. */
1642 if (IS_SX_BOARD (board)) rc = SX_TYPE_SX;
1643 if (IS_CF_BOARD (board)) rc = SX_TYPE_CF;
1644 if (IS_SI_BOARD (board)) rc = SX_TYPE_SI;
1645 if (IS_SI1_BOARD (board)) rc = SX_TYPE_SI;
1646 if (IS_EISA_BOARD (board)) rc = SX_TYPE_SI;
1647 sx_dprintk (SX_DEBUG_FIRMWARE, "returning type= %d\n", rc);
1649 case SXIO_DO_RAMTEST:
1650 if (sx_initialized) /* Already initialized: better not ramtest the board. */
1652 if (IS_SX_BOARD (board)) {
1653 rc = do_memtest (board, 0, 0x7000);
1654 if (!rc) rc = do_memtest (board, 0, 0x7000);
1655 /*if (!rc) rc = do_memtest_w (board, 0, 0x7000);*/
1657 rc = do_memtest (board, 0, 0x7ff8);
1658 /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */
1660 sx_dprintk (SX_DEBUG_FIRMWARE, "returning memtest result= %d\n", rc);
1663 if (sx_initialized) /* Already initialized */
1665 if (!sx_reset (board))
1667 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
1669 tmp = kmalloc (SX_CHUNK_SIZE, GFP_USER);
1670 if (!tmp) return -ENOMEM;
1671 get_user (nbytes, descr++);
1672 get_user (offset, descr++);
1673 get_user (data, descr++);
1674 while (nbytes && data) {
1675 for (i=0;i<nbytes;i += SX_CHUNK_SIZE) {
1676 if (copy_from_user(tmp, (char __user *)data+i,
1677 (i + SX_CHUNK_SIZE >
1678 nbytes) ? nbytes - i :
1683 memcpy_toio(board->base2 + offset + i, tmp,
1684 (i+SX_CHUNK_SIZE>nbytes)?nbytes-i:SX_CHUNK_SIZE);
1687 get_user (nbytes, descr++);
1688 get_user (offset, descr++);
1689 get_user (data, descr++);
1692 sx_nports += sx_init_board (board);
1696 if (sx_initialized) /* Already initialized */
1698 /* This is not allowed until all boards are initialized... */
1699 for (i=0;i<SX_NBOARDS;i++) {
1700 if ( (boards[i].flags & SX_BOARD_PRESENT) &&
1701 !(boards[i].flags & SX_BOARD_INITIALIZED))
1704 for (i=0;i<SX_NBOARDS;i++)
1705 if (!(boards[i].flags & SX_BOARD_PRESENT)) break;
1707 sx_dprintk (SX_DEBUG_FIRMWARE, "initing portstructs, %d boards, "
1708 "%d channels, first board: %d ports\n",
1709 i, sx_nports, boards[0].nports);
1710 rc = sx_init_portstructs (i, sx_nports);
1721 case SXIO_GETGSDEBUG:
1722 case SXIO_SETGSDEBUG:
1725 case SXIO_GETNPORTS:
1729 printk (KERN_WARNING "Unknown ioctl on firmware device (%x).\n", cmd);
1737 static void sx_break (struct tty_struct * tty, int flag)
1739 struct sx_port *port = tty->driver_data;
1745 rv = sx_send_command (port, HS_START, -1, HS_IDLE_BREAK);
1747 rv = sx_send_command (port, HS_STOP, -1, HS_IDLE_OPEN);
1748 if (rv != 1) printk (KERN_ERR "sx: couldn't send break (%x).\n",
1749 read_sx_byte (port->board, CHAN_OFFSET (port, hi_hstat)));
1755 static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1757 struct sx_port *port = tty->driver_data;
1758 return sx_getsignals(port);
1761 static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1762 unsigned int set, unsigned int clear)
1764 struct sx_port *port = tty->driver_data;
1765 int rts = -1, dtr = -1;
1767 if (set & TIOCM_RTS)
1769 if (set & TIOCM_DTR)
1771 if (clear & TIOCM_RTS)
1773 if (clear & TIOCM_DTR)
1776 sx_setsignals(port, dtr, rts);
1777 sx_reconfigure_port(port);
1781 static int sx_ioctl (struct tty_struct * tty, struct file * filp,
1782 unsigned int cmd, unsigned long arg)
1785 struct sx_port *port = tty->driver_data;
1786 void __user *argp = (void __user *)arg;
1789 /* func_enter2(); */
1794 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1795 (unsigned __user *) argp);
1798 if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) {
1799 tty->termios->c_cflag =
1800 (tty->termios->c_cflag & ~CLOCAL) |
1801 (ival ? CLOCAL : 0);
1805 rc = gs_getserial(&port->gs, argp);
1808 rc = gs_setserial(&port->gs, argp);
1820 /* The throttle/unthrottle scheme for the Specialix card is different
1821 * from other drivers and deserves some explanation.
1822 * The Specialix hardware takes care of XON/XOFF
1823 * and CTS/RTS flow control itself. This means that all we have to
1824 * do when signalled by the upper tty layer to throttle/unthrottle is
1825 * to make a note of it here. When we come to read characters from the
1826 * rx buffers on the card (sx_receive_chars()) we look to see if the
1827 * upper layer can accept more (as noted here in sx_rx_throt[]).
1828 * If it can't we simply don't remove chars from the cards buffer.
1829 * When the tty layer can accept chars, we again note that here and when
1830 * sx_receive_chars() is called it will remove them from the cards buffer.
1831 * The card will notice that a ports buffer has drained below some low
1832 * water mark and will unflow control the line itself, using whatever
1833 * flow control scheme is in use for that port. -- Simon Allen
1836 static void sx_throttle (struct tty_struct * tty)
1838 struct sx_port *port = (struct sx_port *)tty->driver_data;
1841 /* If the port is using any type of input flow
1842 * control then throttle the port.
1844 if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) {
1845 port->gs.flags |= SX_RX_THROTTLE;
1851 static void sx_unthrottle (struct tty_struct * tty)
1853 struct sx_port *port = (struct sx_port *)tty->driver_data;
1856 /* Always unthrottle even if flow control is not enabled on
1857 * this port in case we disabled flow control while the port
1860 port->gs.flags &= ~SX_RX_THROTTLE;
1866 /* ********************************************************************** *
1867 * Here are the initialization routines. *
1868 * ********************************************************************** */
1873 static int sx_init_board (struct sx_board *board)
1881 /* This is preceded by downloading the download code. */
1883 board->flags |= SX_BOARD_INITIALIZED;
1885 if (read_sx_byte (board, 0))
1886 /* CF boards may need this. */
1887 write_sx_byte(board,0, 0);
1889 /* This resets the processor again, to make sure it didn't do any
1890 foolish things while we were downloading the image */
1891 if (!sx_reset (board))
1894 sx_start_board (board);
1896 if (!sx_busy_wait_neq (board, 0, 0xff, 0)) {
1897 printk (KERN_ERR "sx: Ooops. Board won't initialize.\n");
1901 /* Ok. So now the processor on the card is running. It gathered
1902 some info for us... */
1903 sx_dprintk (SX_DEBUG_INIT, "The sxcard structure:\n");
1904 if (sx_debug & SX_DEBUG_INIT) my_hd_io (board->base, 0x10);
1905 sx_dprintk (SX_DEBUG_INIT, "the first sx_module structure:\n");
1906 if (sx_debug & SX_DEBUG_INIT) my_hd_io (board->base + 0x80, 0x30);
1908 sx_dprintk (SX_DEBUG_INIT,
1909 "init_status: %x, %dk memory, firmware V%x.%02x,\n",
1910 read_sx_byte (board, 0), read_sx_byte(board, 1),
1911 read_sx_byte (board, 5), read_sx_byte(board, 4));
1913 if (read_sx_byte (board, 0) == 0xff) {
1914 printk (KERN_INFO "sx: No modules found. Sorry.\n");
1921 if (IS_SX_BOARD(board)) {
1922 sx_write_board_word (board, cc_int_count, sx_maxints);
1925 sx_write_board_word (board, cc_int_count, SI_PROCESSOR_CLOCK/8/sx_maxints);
1928 /* grab the first module type... */
1929 /* board->ta_type = mod_compat_type (read_sx_byte (board, 0x80 + 0x08)); */
1930 board->ta_type = mod_compat_type (sx_read_module_byte (board, 0x80, mc_chip));
1933 for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) {
1934 type = sx_read_module_byte (board, addr, mc_chip);
1935 sx_dprintk (SX_DEBUG_INIT, "Module at %x: %d channels\n",
1936 addr, read_sx_byte (board, addr + 2));
1938 chans += sx_read_module_byte (board, addr, mc_type);
1940 sx_dprintk (SX_DEBUG_INIT, "module is an %s, which has %s/%s panels\n",
1942 pan_type_s (sx_read_module_byte (board, addr, mc_mods) & 0xf),
1943 pan_type_s (sx_read_module_byte (board, addr, mc_mods) >> 4));
1945 sx_dprintk (SX_DEBUG_INIT, "CD1400 versions: %x/%x, ASIC version: %x\n",
1946 sx_read_module_byte (board, addr, mc_rev1),
1947 sx_read_module_byte (board, addr, mc_rev2),
1948 sx_read_module_byte (board, addr, mc_mtaasic_rev));
1950 /* The following combinations are illegal: It should theoretically
1951 work, but timing problems make the bus HANG. */
1953 if (mod_compat_type (type) != board->ta_type) {
1954 printk (KERN_ERR "sx: This is an invalid configuration.\n"
1955 "Don't mix TA/MTA/SXDC on the same hostadapter.\n");
1959 if ((IS_EISA_BOARD(board) ||
1960 IS_SI_BOARD(board)) && (mod_compat_type(type) == 4)) {
1961 printk (KERN_ERR "sx: This is an invalid configuration.\n"
1962 "Don't use SXDCs on an SI/XIO adapter.\n");
1966 #if 0 /* Problem fixed: firmware 3.05 */
1967 if (IS_SX_BOARD(board) && (type == TA8)) {
1968 /* There are some issues with the firmware and the DCD/RTS
1969 lines. It might work if you tie them together or something.
1970 It might also work if you get a newer sx_firmware. Therefore
1971 this is just a warning. */
1972 printk (KERN_WARNING "sx: The SX host doesn't work too well "
1973 "with the TA8 adapters.\nSpecialix is working on it.\n");
1979 /* board->flags |= SX_BOARD_PRESENT; */
1980 if(board->irq > 0) {
1981 /* fixed irq, probably PCI */
1982 if(sx_irqmask & (1 << board->irq)) { /* may we use this irq? */
1983 if(request_irq(board->irq, sx_interrupt, IRQF_SHARED | IRQF_DISABLED, "sx", board)) {
1984 printk(KERN_ERR "sx: Cannot allocate irq %d.\n", board->irq);
1989 } else if(board->irq < 0 && sx_irqmask) {
1990 /* auto-allocate irq */
1992 int irqmask = sx_irqmask & (IS_SX_BOARD(board) ? SX_ISA_IRQ_MASK : SI2_ISA_IRQ_MASK);
1993 for(irqnr = 15; irqnr > 0; irqnr--)
1994 if(irqmask & (1 << irqnr))
1995 if(! request_irq(irqnr, sx_interrupt, IRQF_SHARED | IRQF_DISABLED, "sx", board))
1998 printk(KERN_ERR "sx: Cannot allocate IRQ.\n");
2004 /* Found a valid interrupt, start up interrupts! */
2005 sx_dprintk (SX_DEBUG_INIT, "Using irq %d.\n", board->irq);
2006 sx_start_interrupts (board);
2007 board->poll = sx_slowpoll;
2008 board->flags |= SX_IRQ_ALLOCATED;
2010 /* no irq: setup board for polled operation */
2011 board->poll = sx_poll;
2012 sx_dprintk (SX_DEBUG_INIT, "Using poll-interval %d.\n", board->poll);
2015 /* The timer should be initialized anyway: That way we can safely
2016 del_timer it when the module is unloaded. */
2017 init_timer (&board->timer);
2020 board->timer.data = (unsigned long) board;
2021 board->timer.function = sx_pollfunc;
2022 board->timer.expires = jiffies + board->poll;
2023 add_timer (&board->timer);
2029 board->nports = chans;
2030 sx_dprintk (SX_DEBUG_INIT, "returning %d ports.", board->nports);
2037 static void __devinit printheader(void)
2039 static int header_printed;
2041 if (!header_printed) {
2042 printk (KERN_INFO "Specialix SX driver "
2043 "(C) 1998/1999 R.E.Wolff@BitWizard.nl \n");
2044 printk (KERN_INFO "sx: version " __stringify(SX_VERSION) "\n");
2050 static int __devinit probe_sx (struct sx_board *board)
2052 struct vpd_prom vpdp;
2058 if (!IS_CF_BOARD (board)) {
2059 sx_dprintk (SX_DEBUG_PROBE, "Going to verify vpd prom at %p.\n",
2060 board->base + SX_VPD_ROM);
2062 if (sx_debug & SX_DEBUG_PROBE)
2063 my_hd_io(board->base + SX_VPD_ROM, 0x40);
2066 for (i=0;i< sizeof (struct vpd_prom);i++)
2067 *p++ = read_sx_byte (board, SX_VPD_ROM + i*2);
2069 if (sx_debug & SX_DEBUG_PROBE)
2070 my_hd (&vpdp, 0x20);
2072 sx_dprintk (SX_DEBUG_PROBE, "checking identifier...\n");
2074 if (strncmp (vpdp.identifier, SX_VPD_IDENT_STRING, 16) != 0) {
2075 sx_dprintk (SX_DEBUG_PROBE, "Got non-SX identifier: '%s'\n",
2083 if (!IS_CF_BOARD (board)) {
2084 printk (KERN_DEBUG "sx: Found an SX board at %lx\n", board->hw_base);
2085 printk (KERN_DEBUG "sx: hw_rev: %d, assembly level: %d, uniq ID:%08x, ",
2086 vpdp.hwrev, vpdp.hwass, vpdp.uniqid);
2087 printk ( "Manufactured: %d/%d\n",
2088 1970 + vpdp.myear, vpdp.mweek);
2091 if ((((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_PCI_UNIQUEID1) &&
2092 (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_ISA_UNIQUEID1)) {
2093 /* This might be a bit harsh. This was the primary reason the
2094 SX/ISA card didn't work at first... */
2095 printk (KERN_ERR "sx: Hmm. Not an SX/PCI or SX/ISA card. Sorry: giving up.\n");
2099 if (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) == SX_ISA_UNIQUEID1) {
2100 if (((unsigned long)board->hw_base) & 0x8000) {
2101 printk (KERN_WARNING "sx: Warning: There may be hardware problems with the card at %lx.\n", board->hw_base);
2102 printk (KERN_WARNING "sx: Read sx.txt for more info.\n");
2109 /* This resets the processor, and keeps it off the bus. */
2110 if (!sx_reset (board))
2112 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
2114 board->flags |= SX_BOARD_PRESENT;
2122 /* Specialix probes for this card at 32k increments from 640k to 16M.
2123 I consider machines with less than 16M unlikely nowadays, so I'm
2124 not probing above 1Mb. Also, 0xa0000, 0xb0000, are taken by the VGA
2125 card. 0xe0000 and 0xf0000 are taken by the BIOS. That only leaves
2126 0xc0000, 0xc8000, 0xd0000 and 0xd8000 . */
2128 static int __devinit probe_si (struct sx_board *board)
2133 sx_dprintk (SX_DEBUG_PROBE, "Going to verify SI signature hw %lx at %p.\n", board->hw_base,
2134 board->base + SI2_ISA_ID_BASE);
2136 if (sx_debug & SX_DEBUG_PROBE)
2137 my_hd_io(board->base + SI2_ISA_ID_BASE, 0x8);
2139 if (!IS_EISA_BOARD(board)) {
2140 if( IS_SI1_BOARD(board) )
2143 write_sx_byte (board, SI2_ISA_ID_BASE+7-i,i);
2148 if ((read_sx_byte (board, SI2_ISA_ID_BASE+7-i) & 7) != i) {
2155 /* Now we're pretty much convinced that there is an SI board here,
2156 but to prevent trouble, we'd better double check that we don't
2157 have an SI1 board when we're probing for an SI2 board.... */
2159 write_sx_byte (board, SI2_ISA_ID_BASE,0x10);
2160 if ( IS_SI1_BOARD(board)) {
2161 /* This should be an SI1 board, which has this
2162 location writable... */
2163 if (read_sx_byte (board, SI2_ISA_ID_BASE) != 0x10) {
2168 /* This should be an SI2 board, which has the bottom
2169 3 bits non-writable... */
2170 if (read_sx_byte (board, SI2_ISA_ID_BASE) == 0x10) {
2176 /* Now we're pretty much convinced that there is an SI board here,
2177 but to prevent trouble, we'd better double check that we don't
2178 have an SI1 board when we're probing for an SI2 board.... */
2180 write_sx_byte (board, SI2_ISA_ID_BASE,0x10);
2181 if ( IS_SI1_BOARD(board)) {
2182 /* This should be an SI1 board, which has this
2183 location writable... */
2184 if (read_sx_byte (board, SI2_ISA_ID_BASE) != 0x10) {
2189 /* This should be an SI2 board, which has the bottom
2190 3 bits non-writable... */
2191 if (read_sx_byte (board, SI2_ISA_ID_BASE) == 0x10) {
2199 printk (KERN_DEBUG "sx: Found an SI board at %lx\n", board->hw_base);
2200 /* Compared to the SX boards, it is a complete guess as to what
2201 this card is up to... */
2205 /* This resets the processor, and keeps it off the bus. */
2206 if (!sx_reset (board))
2208 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
2210 board->flags |= SX_BOARD_PRESENT;
2216 static const struct tty_operations sx_ops = {
2217 .break_ctl = sx_break,
2221 .put_char = gs_put_char,
2222 .flush_chars = gs_flush_chars,
2223 .write_room = gs_write_room,
2224 .chars_in_buffer = gs_chars_in_buffer,
2225 .flush_buffer = gs_flush_buffer,
2227 .throttle = sx_throttle,
2228 .unthrottle = sx_unthrottle,
2229 .set_termios = gs_set_termios,
2232 .hangup = gs_hangup,
2233 .tiocmget = sx_tiocmget,
2234 .tiocmset = sx_tiocmset,
2237 static int sx_init_drivers(void)
2243 sx_driver = alloc_tty_driver(sx_nports);
2246 sx_driver->owner = THIS_MODULE;
2247 sx_driver->driver_name = "specialix_sx";
2248 sx_driver->name = "ttyX";
2249 sx_driver->major = SX_NORMAL_MAJOR;
2250 sx_driver->type = TTY_DRIVER_TYPE_SERIAL;
2251 sx_driver->subtype = SERIAL_TYPE_NORMAL;
2252 sx_driver->init_termios = tty_std_termios;
2253 sx_driver->init_termios.c_cflag =
2254 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2255 sx_driver->init_termios.c_ispeed = 9600;
2256 sx_driver->init_termios.c_ospeed = 9600;
2257 sx_driver->flags = TTY_DRIVER_REAL_RAW;
2258 tty_set_operations(sx_driver, &sx_ops);
2260 if ((error = tty_register_driver(sx_driver))) {
2261 put_tty_driver(sx_driver);
2262 printk(KERN_ERR "sx: Couldn't register sx driver, error = %d\n",
2270 static int sx_init_portstructs (int nboards, int nports)
2272 struct sx_board *board;
2273 struct sx_port *port;
2280 /* Many drivers statically allocate the maximum number of ports
2281 There is no reason not to allocate them dynamically. Is there? -- REW */
2282 sx_ports = kcalloc(nports, sizeof(struct sx_port), GFP_KERNEL);
2287 for (i = 0; i < nboards; i++) {
2289 board->ports = port;
2290 for (j=0; j < boards[i].nports;j++) {
2291 sx_dprintk (SX_DEBUG_INIT, "initing port %d\n", j);
2292 port->gs.magic = SX_MAGIC;
2293 port->gs.close_delay = HZ/2;
2294 port->gs.closing_wait = 30 * HZ;
2295 port->board = board;
2296 port->gs.rd = &sx_real_driver;
2297 #ifdef NEW_WRITE_LOCKING
2298 port->gs.port_write_mutex = MUTEX;
2300 spin_lock_init(&port->gs.driver_lock);
2302 * Initializing wait queue
2304 init_waitqueue_head(&port->gs.open_wait);
2305 init_waitqueue_head(&port->gs.close_wait);
2313 for (i = 0; i < nboards; i++) {
2315 board->port_base = portno;
2316 /* Possibly the configuration was rejected. */
2317 sx_dprintk (SX_DEBUG_PROBE, "Board has %d channels\n", board->nports);
2318 if (board->nports <= 0) continue;
2319 /* XXX byteorder ?? */
2320 for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) {
2321 chans = sx_read_module_byte (board, addr, mc_type);
2322 sx_dprintk (SX_DEBUG_PROBE, "Module at %x: %d channels\n", addr, chans);
2323 sx_dprintk (SX_DEBUG_PROBE, "Port at");
2324 for (j=0;j<chans;j++) {
2325 /* The "sx-way" is the way it SHOULD be done. That way in the
2326 future, the firmware may for example pack the structures a bit
2327 more efficient. Neil tells me it isn't going to happen anytime
2329 if (IS_SX_BOARD(board))
2330 port->ch_base = sx_read_module_word (board, addr+j*2, mc_chan_pointer);
2332 port->ch_base = addr + 0x100 + 0x300*j;
2334 sx_dprintk (SX_DEBUG_PROBE, " %x", port->ch_base);
2335 port->line = portno++;
2338 sx_dprintk (SX_DEBUG_PROBE, "\n");
2340 /* This has to be done earlier. */
2341 /* board->flags |= SX_BOARD_INITIALIZED; */
2348 static void __exit sx_release_drivers(void)
2351 tty_unregister_driver(sx_driver);
2352 put_tty_driver(sx_driver);
2356 /********************************************************
2357 * Setting bit 17 in the CNTRL register of the PLX 9050 *
2358 * chip forces a retry on writes while a read is pending.*
2359 * This is to prevent the card locking up on Intel Xeon *
2360 * multiprocessor systems with the NX chipset. -- NV *
2361 ********************************************************/
2363 /* Newer cards are produced with this bit set from the configuration
2364 EEprom. As the bit is read/write for the CPU, we can fix it here,
2365 if we detect that it isn't set correctly. -- REW */
2367 static void __devinit fix_sx_pci(struct pci_dev *pdev, struct sx_board *board)
2369 unsigned int hwbase;
2370 void __iomem *rebase;
2373 #define CNTRL_REG_OFFSET 0x50
2374 #define CNTRL_REG_GOODVALUE 0x18260000
2376 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
2377 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
2378 rebase = ioremap(hwbase, 0x80);
2379 t = readl (rebase + CNTRL_REG_OFFSET);
2380 if (t != CNTRL_REG_GOODVALUE) {
2381 printk (KERN_DEBUG "sx: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
2382 writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
2387 static int __devinit sx_pci_probe(struct pci_dev *pdev,
2388 const struct pci_device_id *ent)
2390 struct sx_board *board;
2394 for (i = 0; i < SX_NBOARDS; i++)
2395 if (!(boards[i].flags & SX_BOARD_PRESENT))
2398 if (i == SX_NBOARDS)
2401 retval = pci_enable_device(pdev);
2407 board->flags &= ~SX_BOARD_TYPE;
2408 board->flags |= (pdev->subsystem_vendor == 0x200) ? SX_PCI_BOARD :
2411 /* CF boards use base address 3.... */
2412 if (IS_CF_BOARD (board))
2413 board->hw_base = pci_resource_start(pdev, 3);
2415 board->hw_base = pci_resource_start(pdev, 2);
2417 board->base = ioremap(board->hw_base, WINDOW_LEN (board));
2419 dev_err(&pdev->dev, "ioremap failed\n");
2423 /* Most of the stuff on the CF board is offset by 0x18000 .... */
2424 if (IS_CF_BOARD (board))
2425 board->base += 0x18000;
2427 board->irq = pdev->irq;
2429 dev_info(&pdev->dev, "Got a specialix card: %p(%d) %x.\n", board->base,
2430 board->irq, board->flags);
2432 if (!probe_sx(board)) {
2437 fix_sx_pci(pdev, board);
2439 pci_set_drvdata(pdev, board);
2443 iounmap(board->base2);
2448 static void __devexit sx_pci_remove(struct pci_dev *pdev)
2450 struct sx_board *board = pci_get_drvdata(pdev);
2452 if (board->flags & SX_BOARD_INITIALIZED) {
2453 /* The board should stop messing with us. (actually I mean the
2456 if ((board->irq) && (board->flags & SX_IRQ_ALLOCATED))
2457 free_irq(board->irq, board);
2459 /* It is safe/allowed to del_timer a non-active timer */
2460 del_timer(&board->timer);
2461 iounmap(board->base);
2463 board->flags &= ~(SX_BOARD_INITIALIZED|SX_BOARD_PRESENT);
2467 /* Specialix has a whole bunch of cards with 0x2000 as the device ID. They say
2468 its because the standard requires it. So check for SUBVENDOR_ID. */
2469 static struct pci_device_id sx_pci_tbl[] = {
2470 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
2471 .subvendor = 0x0200, .subdevice = PCI_ANY_ID },
2472 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
2473 .subvendor = 0x0300, .subdevice = PCI_ANY_ID },
2476 MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
2478 static struct pci_driver sx_pcidriver = {
2480 .id_table = sx_pci_tbl,
2481 .probe = sx_pci_probe,
2482 .remove = __devexit_p(sx_pci_remove)
2485 static int __init sx_init(void)
2490 struct sx_board *board;
2493 sx_dprintk (SX_DEBUG_INIT, "Initing sx module... (sx_debug=%d)\n", sx_debug);
2494 if (abs ((long) (&sx_debug) - sx_debug) < 0x10000) {
2495 printk (KERN_WARNING "sx: sx_debug is an address, instead of a value. "
2497 printk ("(%p)\n", &sx_debug);
2501 if (misc_register(&sx_fw_device) < 0) {
2502 printk(KERN_ERR "SX: Unable to register firmware loader driver.\n");
2506 for (i=0;i<NR_SX_ADDRS;i++) {
2507 board = &boards[found];
2508 board->hw_base = sx_probe_addrs[i];
2510 board->base = ioremap(board->hw_base, SX_WINDOW_LEN);
2511 board->flags &= ~SX_BOARD_TYPE;
2512 board->flags |= SX_ISA_BOARD;
2513 board->irq = sx_irqmask?-1:0;
2515 if (probe_sx (board)) {
2518 iounmap(board->base);
2522 for (i=0;i<NR_SI_ADDRS;i++) {
2523 board = &boards[found];
2524 board->hw_base = si_probe_addrs[i];
2526 board->base = ioremap(board->hw_base, SI2_ISA_WINDOW_LEN);
2527 board->flags &= ~SX_BOARD_TYPE;
2528 board->flags |= SI_ISA_BOARD;
2529 board->irq = sx_irqmask ?-1:0;
2531 if (probe_si (board)) {
2534 iounmap (board->base);
2537 for (i=0;i<NR_SI1_ADDRS;i++) {
2538 board = &boards[found];
2539 board->hw_base = si1_probe_addrs[i];
2541 board->base = ioremap(board->hw_base, SI1_ISA_WINDOW_LEN);
2542 board->flags &= ~SX_BOARD_TYPE;
2543 board->flags |= SI1_ISA_BOARD;
2544 board->irq = sx_irqmask ?-1:0;
2546 if (probe_si (board)) {
2549 iounmap (board->base);
2553 sx_dprintk(SX_DEBUG_PROBE, "Probing for EISA cards\n");
2554 for(eisa_slot=0x1000; eisa_slot<0x10000; eisa_slot+=0x1000)
2556 if((inb(eisa_slot+0xc80)==0x4d) &&
2557 (inb(eisa_slot+0xc81)==0x98))
2559 sx_dprintk(SX_DEBUG_PROBE, "%s : Signature found in EISA slot %d, Product %d Rev %d\n",
2560 "XIO", (eisa_slot>>12), inb(eisa_slot+0xc82), inb(eisa_slot+0xc83));
2562 board = &boards[found];
2563 board->eisa_base = eisa_slot;
2564 board->flags &= ~SX_BOARD_TYPE;
2565 board->flags |= SI_EISA_BOARD;
2567 board->hw_base = (((inb(0xc01+eisa_slot) << 8) + inb(0xc00+eisa_slot)) << 16);
2569 board->base = ioremap(board->hw_base, SI2_EISA_WINDOW_LEN);
2571 sx_dprintk(SX_DEBUG_PROBE, "IO hw_base address: %lx\n", board->hw_base);
2572 sx_dprintk(SX_DEBUG_PROBE, "base: %p\n", board->base);
2573 board->irq = inb(board->eisa_base+0xc02)>>4;
2574 sx_dprintk(SX_DEBUG_PROBE, "IRQ: %d\n", board->irq);
2582 retval = pci_register_driver(&sx_pcidriver);
2585 printk (KERN_INFO "sx: total of %d boards detected.\n", found);
2587 } else if (retval) {
2588 misc_deregister(&sx_fw_device);
2596 static void __exit sx_exit (void)
2599 struct sx_board *board;
2602 pci_unregister_driver(&sx_pcidriver);
2603 for (i = 0; i < SX_NBOARDS; i++) {
2605 if (board->flags & SX_BOARD_INITIALIZED) {
2606 sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up board at %p\n", board->base);
2607 /* The board should stop messing with us.
2608 (actually I mean the interrupt) */
2610 if ((board->irq) && (board->flags & SX_IRQ_ALLOCATED))
2611 free_irq (board->irq, board);
2613 /* It is safe/allowed to del_timer a non-active timer */
2614 del_timer (& board->timer);
2615 iounmap(board->base);
2618 if (misc_deregister(&sx_fw_device) < 0) {
2619 printk (KERN_INFO "sx: couldn't deregister firmware loader device\n");
2621 sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up drivers (%d)\n", sx_initialized);
2623 sx_release_drivers ();
2629 module_init(sx_init);
2630 module_exit(sx_exit);