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 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.26 1999/08/05 15:22:14 wolff
38 * - Reformatted to Linus' liking.
40 * Revision 1.25 1999/07/30 14:24:08 wolff
41 * Had accidentally left "gs_debug" set to "-1" instead of "off" (=0).
43 * Revision 1.24 1999/07/28 09:41:52 wolff
44 * - I noticed the remark about use-count straying in sx.txt. I checked
45 * sx_open, and found a few places where that could happen. I hope it's
48 * Revision 1.23 1999/07/28 08:56:06 wolff
49 * - Fixed crash when sx_firmware run twice.
50 * - Added sx_slowpoll as a module parameter (I guess nobody really wanted
51 * to change it from the default... )
52 * - Fixed a stupid editing problem I introduced in 1.22.
53 * - Fixed dropping characters on a termios change.
55 * Revision 1.22 1999/07/26 21:01:43 wolff
56 * Russell Brown noticed that I had overlooked 4 out of six modem control
57 * signals in sx_getsignals. Ooops.
59 * Revision 1.21 1999/07/23 09:11:33 wolff
60 * I forgot to free dynamically allocated memory when the driver is unloaded.
62 * Revision 1.20 1999/07/20 06:25:26 wolff
63 * The "closing wait" wasn't honoured. Thanks to James Griffiths for
66 * Revision 1.19 1999/07/11 08:59:59 wolff
67 * Fixed an oops in close, when an open was pending. Changed the memtest
68 * a bit. Should also test the board in word-mode, however my card fails the
69 * memtest then. I still have to figure out what is wrong...
71 * Revision 1.18 1999/06/10 09:38:42 wolff
72 * Changed the format of the firmware revision from %04x to %x.%02x .
74 * Revision 1.17 1999/06/04 09:44:35 wolff
75 * fixed problem: reference to pci stuff when config_pci was off...
76 * Thanks to Jorge Novo for noticing this.
78 * Revision 1.16 1999/06/02 08:30:15 wolff
79 * added/removed the workaround for the DCD bug in the Firmware.
80 * A bit more debugging code to locate that...
82 * Revision 1.15 1999/06/01 11:35:30 wolff
83 * when DCD is left low (floating?), on TA's the firmware first tells us
84 * that DCD is high, but after a short while suddenly comes to the
85 * conclusion that it is low. All this would be fine, if it weren't that
86 * Unix requires us to send a "hangup" signal in that case. This usually
87 * all happens BEFORE the program has had a chance to ioctl the device
90 * Revision 1.14 1999/05/25 11:18:59 wolff
92 * Added checks for return code of sx_sendcommand.
93 * Don't issue "reconfig" if port isn't open yet. (bit us on TA modules...)
95 * Revision 1.13 1999/04/29 15:18:01 wolff
96 * Fixed an "oops" that showed on SuSE 6.0 systems.
97 * Activate DTR again after stty 0.
99 * Revision 1.12 1999/04/29 07:49:52 wolff
100 * Improved "stty 0" handling a bit. (used to change baud to 9600 assuming
101 * the connection would be dropped anyway. That is not always the case,
102 * and confuses people).
103 * Told the card to always monitor the modem signals.
104 * Added support for dynamic gs_debug adjustments.
105 * Now tells the rest of the system the number of ports.
107 * Revision 1.11 1999/04/24 11:11:30 wolff
108 * Fixed two stupid typos in the memory test.
110 * Revision 1.10 1999/04/24 10:53:39 wolff
111 * Added some of Christian's suggestions.
112 * Fixed an HW_COOK_IN bug (ISIG was not in I_OTHER. We used to trust the
113 * card to send the signal to the process.....)
115 * Revision 1.9 1999/04/23 07:26:38 wolff
116 * Included Christian Lademann's 2.0 compile-warning fixes and interrupt
117 * assignment redesign.
118 * Cleanup of some other stuff.
120 * Revision 1.8 1999/04/16 13:05:30 wolff
121 * fixed a DCD change unnoticed bug.
123 * Revision 1.7 1999/04/14 22:19:51 wolff
124 * Fixed typo that showed up in 2.0.x builds (get_user instead of Get_user!)
126 * Revision 1.6 1999/04/13 18:40:20 wolff
127 * changed misc-minor to 161, as assigned by HPA.
129 * Revision 1.5 1999/04/13 15:12:25 wolff
130 * Fixed use-count leak when "hangup" occurred.
131 * Added workaround for a stupid-PCIBIOS bug.
134 * Revision 1.4 1999/04/01 22:47:40 wolff
135 * Fixed < 1M linux-2.0 problem.
136 * (vremap isn't compatible with ioremap in that case)
138 * Revision 1.3 1999/03/31 13:45:45 wolff
139 * Firmware loading is now done through a separate IOCTL.
141 * Revision 1.2 1999/03/28 12:22:29 wolff
144 * Revision 1.1 1999/03/28 12:10:34 wolff
145 * Readying for release on 2.0.x (sorry David, 1.01 becomes 1.1 for RCS).
147 * Revision 0.12 1999/03/28 09:20:10 wolff
148 * Fixed problem in 0.11, continueing cleanup.
150 * Revision 0.11 1999/03/28 08:46:44 wolff
153 * Revision 0.10 1999/03/28 08:09:43 wolff
154 * Fixed loosing characters on close.
156 * Revision 0.9 1999/03/21 22:52:01 wolff
157 * Ported back to 2.2.... (minor things)
159 * Revision 0.8 1999/03/21 22:40:33 wolff
162 * Revision 0.7 1999/03/21 19:06:34 wolff
163 * Fixed hangup processing.
165 * Revision 0.6 1999/02/05 08:45:14 wolff
166 * fixed real_raw problems. Inclusion into kernel imminent.
168 * Revision 0.5 1998/12/21 23:51:06 wolff
169 * Snatched a nasty bug: sx_transmit_chars was getting re-entered, and it
170 * shouldn't have. THATs why I want to have transmit interrupts even when
171 * the buffer is empty.
173 * Revision 0.4 1998/12/17 09:34:46 wolff
174 * PPP works. ioctl works. Basically works!
176 * Revision 0.3 1998/12/15 13:05:18 wolff
177 * It works! Wow! Gotta start implementing IOCTL and stuff....
179 * Revision 0.2 1998/12/01 08:33:53 wolff
180 * moved over to 2.1.130
182 * Revision 0.1 1998/11/03 21:23:51 wolff
183 * Initial revision. Detects SX card.
188 #define RCS_ID "$Id: sx.c,v 1.26 1999/08/05 15:22:14 wolff Exp $"
189 #define RCS_REV "$Revision: 1.26 $"
192 #include <linux/module.h>
193 #include <linux/config.h>
194 #include <linux/kdev_t.h>
196 #include <linux/kernel.h>
197 #include <linux/sched.h>
198 #include <linux/ioport.h>
199 #include <linux/interrupt.h>
200 #include <linux/errno.h>
201 #include <linux/tty.h>
202 #include <linux/tty_flip.h>
203 #include <linux/mm.h>
204 #include <linux/serial.h>
205 #include <linux/fcntl.h>
206 #include <linux/major.h>
207 #include <linux/delay.h>
208 #include <linux/tqueue.h>
209 #include <linux/version.h>
210 #include <linux/pci.h>
211 #include <linux/malloc.h>
212 #include <linux/miscdevice.h>
214 /* The 3.0.0 version of sxboards/sxwindow.h uses BYTE and WORD.... */
218 /* .... but the 3.0.4 version uses _u8 and _u16. */
222 #include "sxboards.h"
223 #include "sxwindow.h"
226 /* I don't think that this driver can handle more than 256 ports on
227 one machine. You'll have to increase the number of boards in sx.h
228 if you want more than 4 boards. */
231 /* ************************************************************** */
232 /* * This section can be removed when 2.0 becomes outdated.... * */
233 /* ************************************************************** */
236 #if LINUX_VERSION_CODE < 0x020100 /* Less than 2.1.0 */
239 #if LINUX_VERSION_CODE < 0x020200 /* less than 2.2.x */
240 #warning "Please use a 2.2.x kernel. "
242 #if LINUX_VERSION_CODE < 0x020300 /* less than 2.3.x */
252 /* Here is the section that makes the 2.2 compatible driver source
253 work for 2.0 too! We mostly try to adopt the "new thingies" from 2.2,
254 and provide for compatibility stuff here if possible. */
256 #include <linux/bios32.h>
258 #define Get_user(a,b) a = get_user(b)
259 #define Put_user(a,b) 0,put_user(a,b)
260 #define copy_to_user(a,b,c) memcpy_tofs(a,b,c)
262 static inline int copy_from_user(void *to
,const void *from
, int c
)
264 memcpy_fromfs(to
, from
, c
);
268 #define pci_present pcibios_present
269 #define pci_read_config_word pcibios_read_config_word
270 #define pci_read_config_dword pcibios_read_config_dword
272 static inline unsigned char get_irq (unsigned char bus
, unsigned char fn
)
275 pcibios_read_config_byte (bus
, fn
, PCI_INTERRUPT_LINE
, &t
);
279 static inline void *ioremap(unsigned long base
, long length
)
281 if (base
< 0x100000) return (void *)base
;
282 return vremap (base
, length
);
285 #define my_iounmap(x, b) (((long)x<0x100000)?0:vfree ((void*)x))
287 #define capable(x) suser()
289 #define queue_task queue_task_irq_off
290 #define tty_flip_buffer_push(tty) queue_task(&tty->flip.tqueue, &tq_timer)
291 #define signal_pending(current) (current->signal & ~current->blocked)
292 #define schedule_timeout(to) do {current->timeout = jiffies + (to);schedule ();} while (0)
293 #define time_after(t1,t2) (((long)t1-t2) > 0)
296 #define test_and_set_bit(nr, addr) set_bit(nr, addr)
297 #define test_and_clear_bit(nr, addr) clear_bit(nr, addr)
299 /* Not yet implemented on 2.0 */
300 #define ASYNC_SPD_SHI -1
301 #define ASYNC_SPD_WARP -1
304 /* Ugly hack: the driver_name doesn't exist in 2.0.x . So we define it
305 to the "name" field that does exist. As long as the assignments are
306 done in the right order, there is nothing to worry about. */
307 #define driver_name name
309 /* Should be in a header somewhere. They are in tty.h on 2.2 */
310 #define TTY_HW_COOK_OUT 14 /* Flag to tell ntty what we can handle */
311 #define TTY_HW_COOK_IN 15 /* in hardware - output and input */
313 /* The return type of a "close" routine. */
315 #define NO_ERROR /* Nothing */
319 /* The 2.2.x compatibility section. */
320 #include <asm/uaccess.h>
323 #define Get_user(a,b) get_user(a,b)
324 #define Put_user(a,b) put_user(a,b)
325 #define get_irq(pdev) pdev->irq
330 #define my_iounmap(x,b) (iounmap((char *)(b)))
335 /* These are new in 2.3. The source now uses 2.3 syntax, and here is
336 the compatibility define... */
337 #define wait_queue_head_t struct wait_queue *
338 #define DECLARE_MUTEX(name) struct semaphore name = MUTEX
339 #define DECLARE_WAITQUEUE(wait, current) struct wait_queue wait = { current, NULL }
343 #undef RS_EVENT_WRITE_WAKEUP
344 #define RS_EVENT_WRITE_WAKEUP 0
347 #include "generic_serial.h"
351 /* ************************************************************** */
352 /* * End of compatibility section.. * */
353 /* ************************************************************** */
357 /* Why the hell am I defining these here? */
358 #define SX_TYPE_NORMAL 1
359 #define SX_TYPE_CALLOUT 2
361 #ifndef SX_NORMAL_MAJOR
362 /* This allows overriding on the compiler commandline, or in a "major.h"
363 include or something like that */
364 #define SX_NORMAL_MAJOR 32
365 #define SX_CALLOUT_MAJOR 33
368 #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
369 #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
374 /* Configurable options:
375 (Don't be too sure that it'll work if you toggle them) */
377 /* Am I paranoid or not ? ;-) */
378 #undef SX_PARANOIA_CHECK
381 /* 20 -> 2000 per second. The card should rate-limit interrupts at 100
382 Hz, but it is user configurable. I don't recommend going above 1000
383 Hz. The interrupt ratelimit might trigger if the interrupt is
384 shared with a very active other device. */
385 #define IRQ_RATE_LIMIT 20
387 /* Sharing interrupts is possible now. If the other device wants more
388 than 2000 interrupts per second, we'd gracefully decline further
389 interrupts. That's not what we want. On the other hand, if the
390 other device interrupts 2000 times a second, don't use the SX
391 interrupt. Use polling. */
392 #undef IRQ_RATE_LIMIT
396 /* Not implemented */
398 * The following defines are mostly for testing purposes. But if you need
399 * some nice reporting in your syslog, you can define them also.
401 #define SX_REPORT_FIFO
402 #define SX_REPORT_OVERRUN
406 /* Function prototypes */
407 static void sx_disable_tx_interrupts (void * ptr
);
408 static void sx_enable_tx_interrupts (void * ptr
);
409 static void sx_disable_rx_interrupts (void * ptr
);
410 static void sx_enable_rx_interrupts (void * ptr
);
411 static int sx_get_CD (void * ptr
);
412 static void sx_shutdown_port (void * ptr
);
413 static void sx_set_real_termios (void *ptr
);
414 static void sx_hungup (void *ptr
);
415 static void sx_close (void *ptr
);
416 static int sx_chars_in_buffer (void * ptr
);
417 static int sx_init_board (struct sx_board
*board
);
418 static int sx_init_portstructs (int nboards
, int nports
);
419 static int sx_fw_ioctl (struct inode
*inode
, struct file
*filp
,
420 unsigned int cmd
, unsigned long arg
);
421 static int sx_fw_open(struct inode
*inode
, struct file
*filp
);
422 static INT
sx_fw_release(struct inode
*inode
, struct file
*filp
);
423 static int sx_init_drivers(void);
424 void my_hd (unsigned char *addr
, int len
);
428 static struct tty_driver sx_driver
, sx_callout_driver
;
430 static struct tty_struct
* sx_table
[SX_NPORTS
] = { NULL
, };
431 static struct termios
** sx_termios
;
432 static struct termios
** sx_termios_locked
;
434 struct sx_board boards
[SX_NBOARDS
];
435 struct sx_port
*sx_ports
;
437 int sx_initialized
= 0;
442 /* You can have the driver poll your card.
443 - Set sx_poll to 1 to poll every timer tick (10ms on Intel).
444 This is used when the card cannot use an interrupt for some reason.
446 - set sx_slowpoll to 100 to do an extra poll once a second (on Intel). If
447 the driver misses an interrupt (report this if it DOES happen to you!)
448 everything will continue to work....
453 /* The card limits the number of interrupts per second.
454 At 115k2 "100" should be sufficient.
455 If you're using higher baudrates, you can increase this...
458 int sx_maxints
= 100;
460 /* These are the only open spaces in my computer. Yours may have more
462 int sx_probe_addrs
[]= {0xc0000, 0xd0000, 0xe0000,
463 0xc8000, 0xd8000, 0xe8000};
464 int si_probe_addrs
[]= {0xc0000, 0xd0000, 0xe0000,
465 0xc8000, 0xd8000, 0xe8000};
467 #define NR_SX_ADDRS (sizeof(sx_probe_addrs)/sizeof (int))
468 #define NR_SI_ADDRS (sizeof(si_probe_addrs)/sizeof (int))
471 /* Set the mask to all-ones. This alas, only supports 32 interrupts.
472 Some architectures may need more. */
477 MODULE_PARM(sx_poll
, "i");
478 MODULE_PARM(sx_slowpoll
, "i");
479 MODULE_PARM(sx_maxints
, "i");
480 MODULE_PARM(sx_debug
, "i");
481 MODULE_PARM(sx_irqmask
, "i");
485 static struct real_driver sx_real_driver
= {
486 sx_disable_tx_interrupts
,
487 sx_enable_tx_interrupts
,
488 sx_disable_rx_interrupts
,
489 sx_enable_rx_interrupts
,
501 This driver can spew a whole lot of debugging output at you. If you
502 need maximum performance, you should disable the DEBUG define. To
503 aid in debugging in the field, I'm leaving the compile-time debug
504 features enabled, and disable them "runtime". That allows me to
505 instruct people with problems to enable debugging without requiring
512 #define sx_dprintk(f, str...) if (sx_debug & f) printk (str)
514 #define sx_dprintk(f, str...) /* nothing */
519 #define func_enter() sx_dprintk (SX_DEBUG_FLOW, "sx: enter " __FUNCTION__ "\n")
520 #define func_exit() sx_dprintk (SX_DEBUG_FLOW, "sx: exit " __FUNCTION__ "\n")
522 #define func_enter2() sx_dprintk (SX_DEBUG_FLOW, "sx: enter " __FUNCTION__ \
523 "(port %d)\n", port->line)
529 * Firmware loader driver specific routines
533 static struct file_operations sx_fw_fops
= {
550 struct miscdevice sx_fw_device
= {
551 SXCTL_MISC_MINOR
, "sxctl", &sx_fw_fops
558 #ifdef SX_PARANOIA_CHECK
560 /* This doesn't work. Who's paranoid around here? Not me! */
562 static inline int sx_paranoia_check(struct sx_port
const * port
,
563 kdev_t device
, const char *routine
)
566 static const char *badmagic
=
567 KERN_ERR
"sx: Warning: bad sx port magic number for device %s in %s\n";
568 static const char *badinfo
=
569 KERN_ERR
"sx: Warning: null sx port for device %s in %s\n";
572 printk(badinfo
, kdevname(device
), routine
);
575 if (port
->magic
!= SX_MAGIC
) {
576 printk(badmagic
, kdevname(device
), routine
);
583 #define sx_paranoia_check(a,b,c) 0
586 /* The timeouts. First try 30 times as fast as possible. Then give
587 the card some time to breathe between accesses. (Otherwise the
588 processor on the card might not be able to access its OWN bus... */
591 #define TIMEOUT_2 1000000
594 /* This needs redoing for Alpha -- REW -- Done. */
596 inline void write_sx_byte (struct sx_board
*board
, int offset
, u8 byte
)
598 writeb (byte
, board
->base
+offset
);
601 inline u8
read_sx_byte (struct sx_board
*board
, int offset
)
603 return readb (board
->base
+offset
);
607 inline void write_sx_word (struct sx_board
*board
, int offset
, u16 word
)
609 writew (word
, board
->base
+offset
);
612 inline u16
read_sx_word (struct sx_board
*board
, int offset
)
614 return readw (board
->base
+ offset
);
618 int sx_busy_wait_eq (struct sx_board
*board
,
627 for (i
=0; i
< TIMEOUT_1
> 0;i
++)
628 if ((read_sx_byte (board
, offset
) & mask
) == correctval
) {
633 for (i
=0; i
< TIMEOUT_2
> 0;i
++) {
634 if ((read_sx_byte (board
, offset
) & mask
) == correctval
) {
646 int sx_busy_wait_neq (struct sx_board
*board
,
655 for (i
=0; i
< TIMEOUT_1
> 0;i
++)
656 if ((read_sx_byte (board
, offset
) & mask
) != badval
) {
661 for (i
=0; i
< TIMEOUT_2
> 0;i
++) {
662 if ((read_sx_byte (board
, offset
) & mask
) != badval
) {
675 /* 5.6.4 of 6210028 r2.3 */
676 int sx_reset (struct sx_board
*board
)
680 if (IS_SX_BOARD (board
)) {
682 write_sx_byte (board
, SX_CONFIG
, 0);
683 write_sx_byte (board
, SX_RESET
, 1); /* Value doesn't matter */
685 if (!sx_busy_wait_eq (board
, SX_RESET_STATUS
, 1, 0)) {
686 printk (KERN_INFO
"sx: Card doesn't respond to reset....\n");
690 /* Gory details of the SI/ISA board */
691 write_sx_byte (board
, SI2_ISA_RESET
, SI2_ISA_RESET_SET
);
692 write_sx_byte (board
, SI2_ISA_IRQ11
, SI2_ISA_IRQ11_CLEAR
);
693 write_sx_byte (board
, SI2_ISA_IRQ12
, SI2_ISA_IRQ12_CLEAR
);
694 write_sx_byte (board
, SI2_ISA_IRQ15
, SI2_ISA_IRQ15_CLEAR
);
695 write_sx_byte (board
, SI2_ISA_INTCLEAR
, SI2_ISA_INTCLEAR_CLEAR
);
696 write_sx_byte (board
, SI2_ISA_IRQSET
, SI2_ISA_IRQSET_CLEAR
);
704 /* This doesn't work on machines where "NULL" isn't 0 */
705 /* If you have one of those, someone will need to write
706 the equivalent of this, which will amount to about 3 lines. I don't
707 want to complicate this right now. -- REW
708 (See, I do write comments every now and then :-) */
709 #define OFFSETOF(strct, elem) ((long)&(((struct strct *)NULL)->elem))
712 #define CHAN_OFFSET(port,elem) (port->ch_base + OFFSETOF (_SXCHANNEL, elem))
713 #define MODU_OFFSET(board,addr,elem) (addr + OFFSETOF (_SXMODULE, elem))
714 #define BRD_OFFSET(board,elem) (OFFSETOF (_SXCARD, elem))
717 #define sx_write_channel_byte(port, elem, val) \
718 write_sx_byte (port->board, CHAN_OFFSET (port, elem), val)
720 #define sx_read_channel_byte(port, elem) \
721 read_sx_byte (port->board, CHAN_OFFSET (port, elem))
723 #define sx_write_channel_word(port, elem, val) \
724 write_sx_word (port->board, CHAN_OFFSET (port, elem), val)
726 #define sx_read_channel_word(port, elem) \
727 read_sx_word (port->board, CHAN_OFFSET (port, elem))
730 #define sx_write_module_byte(board, addr, elem, val) \
731 write_sx_byte (board, MODU_OFFSET (board, addr, elem), val)
733 #define sx_read_module_byte(board, addr, elem) \
734 read_sx_byte (board, MODU_OFFSET (board, addr, elem))
736 #define sx_write_module_word(board, addr, elem, val) \
737 write_sx_word (board, MODU_OFFSET (board, addr, elem), val)
739 #define sx_read_module_word(board, addr, elem) \
740 read_sx_word (board, MODU_OFFSET (board, addr, elem))
743 #define sx_write_board_byte(board, elem, val) \
744 write_sx_byte (board, BRD_OFFSET (board, elem), val)
746 #define sx_read_board_byte(board, elem) \
747 read_sx_byte (board, BRD_OFFSET (board, elem))
749 #define sx_write_board_word(board, elem, val) \
750 write_sx_word (board, BRD_OFFSET (board, elem), val)
752 #define sx_read_board_word(board, elem) \
753 read_sx_word (board, BRD_OFFSET (board, elem))
756 int sx_start_board (struct sx_board
*board
)
758 if (IS_SX_BOARD (board
)) {
759 write_sx_byte (board
, SX_CONFIG
, SX_CONF_BUSEN
);
761 /* Don't bug me about the clear_set.
762 I haven't the foggiest idea what it's about -- REW*/
763 write_sx_byte (board
, SI2_ISA_RESET
, SI2_ISA_RESET_CLEAR
);
764 write_sx_byte (board
, SI2_ISA_INTCLEAR
, SI2_ISA_INTCLEAR_SET
);
769 #define SX_IRQ_REG_VAL(board) \
770 ((board->flags & SX_ISA_BOARD)?(board->irq << 4):0)
772 /* Note. The SX register is write-only. Therefore, we have to enable the
773 bus too. This is a no-op, if you don't mess with this driver... */
774 int sx_start_interrupts (struct sx_board
*board
)
777 /* Don't call this with board->irq == 0 */
779 if (IS_SX_BOARD(board
)) {
780 write_sx_byte (board
, SX_CONFIG
, SX_IRQ_REG_VAL (board
) |
784 switch (board
->irq
) {
785 case 11:write_sx_byte (board
, SI2_ISA_IRQ11
, SI2_ISA_IRQ11_SET
);break;
786 case 12:write_sx_byte (board
, SI2_ISA_IRQ12
, SI2_ISA_IRQ12_SET
);break;
787 case 15:write_sx_byte (board
, SI2_ISA_IRQ15
, SI2_ISA_IRQ15_SET
);break;
788 default:printk (KERN_INFO
"sx: SI/XIO card doesn't support interrupt %d.\n",
792 write_sx_byte (board
, SI2_ISA_INTCLEAR
, SI2_ISA_INTCLEAR_SET
);
799 int sx_send_command (struct sx_port
*port
,
805 write_sx_byte (port
->board
, CHAN_OFFSET (port
, hi_hstat
), command
);
807 return sx_busy_wait_eq (port
->board
, CHAN_OFFSET (port
, hi_hstat
), mask
, newstat
);
811 char *mod_type_s (int module_type
)
813 switch (module_type
) {
814 case TA4
: return "TA4";
815 case TA8
: return "TA8";
816 case TA4_ASIC
: return "TA4_ASIC";
817 case TA8_ASIC
: return "TA8_ASIC";
818 case MTA_CD1400
:return "MTA_CD1400";
819 case SXDC
: return "SXDC";
820 default:return "Unknown/invalid";
825 char *pan_type_s (int pan_type
)
828 case MOD_RS232DB25
: return "MOD_RS232DB25";
829 case MOD_RS232RJ45
: return "MOD_RS232RJ45";
830 case MOD_RS422DB25
: return "MOD_RS422DB25";
831 case MOD_PARALLEL
: return "MOD_PARALLEL";
832 case MOD_2_RS232DB25
: return "MOD_2_RS232DB25";
833 case MOD_2_RS232RJ45
: return "MOD_2_RS232RJ45";
834 case MOD_2_RS422DB25
: return "MOD_2_RS422DB25";
835 case MOD_RS232DB25MALE
: return "MOD_RS232DB25MALE";
836 case MOD_2_PARALLEL
: return "MOD_2_PARALLEL";
837 case MOD_BLANK
: return "empty";
838 default:return "invalid";
843 int mod_compat_type (int module_type
)
845 return module_type
>> 4;
849 static void sx_setsignals (struct sx_port
*port
, int dtr
, int rts
)
854 t
= sx_read_channel_byte (port
, hi_op
);
855 if (dtr
>= 0) t
= dtr
? (t
| OP_DTR
): (t
& ~OP_DTR
);
856 if (rts
>= 0) t
= rts
? (t
| OP_RTS
): (t
& ~OP_RTS
);
857 sx_write_channel_byte (port
, hi_op
, t
);
858 sx_dprintk (SX_DEBUG_MODEMSIGNALS
, "setsignals: %d/%d\n", dtr
, rts
);
864 static int sx_getsignals (struct sx_port
*port
)
868 o_stat
= sx_read_channel_byte (port
, hi_op
);
869 i_stat
= sx_read_channel_byte (port
, hi_ip
);
871 sx_dprintk (SX_DEBUG_MODEMSIGNALS
, "getsignals: %d/%d (%d/%d) %02x/%02x\n",
872 (o_stat
& OP_DTR
) != 0, (o_stat
& OP_RTS
) != 0,
873 port
->c_dcd
, sx_get_CD (port
),
874 sx_read_channel_byte (port
, hi_ip
),
875 sx_read_channel_byte (port
, hi_state
));
877 return (((o_stat
& OP_DTR
)?TIOCM_DTR
:0) |
878 ((o_stat
& OP_RTS
)?TIOCM_RTS
:0) |
879 ((i_stat
& IP_CTS
)?TIOCM_CTS
:0) |
880 ((i_stat
& IP_DCD
)?TIOCM_CAR
:0) |
881 ((i_stat
& IP_DSR
)?TIOCM_DSR
:0) |
882 ((i_stat
& IP_RI
)?TIOCM_RNG
:0)
887 static void sx_set_baud (struct sx_port
*port
)
891 if (port
->board
->ta_type
== MOD_SXDC
) {
892 switch (port
->gs
.baud
) {
893 /* Save some typing work... */
894 #define e(x) case x:t= BAUD_ ## x ; break
895 e(50);e(75);e(110);e(150);e(200);e(300);e(600);
896 e(1200);e(1800);e(2000);e(2400);e(4800);e(7200);
897 e(9600);e(14400);e(19200);e(28800);e(38400);
898 e(56000);e(57600);e(64000);e(76800);e(115200);
899 e(128000);e(150000);e(230400);e(256000);e(460800);
901 case 134 :t
= BAUD_134_5
; break;
905 /* Can I return "invalid"? */
907 printk (KERN_INFO
"sx: unsupported baud rate: %d.\n", port
->gs
.baud
);
912 /* The baud rate is not set to 0, so we're enabeling DTR... -- REW */
913 sx_setsignals (port
, 1, -1);
914 /* XXX This is not TA & MTA compatible */
915 sx_write_channel_byte (port
, hi_csr
, 0xff);
917 sx_write_channel_byte (port
, hi_txbaud
, t
);
918 sx_write_channel_byte (port
, hi_rxbaud
, t
);
920 sx_setsignals (port
, 0, -1);
923 switch (port
->gs
.baud
) {
924 #define e(x) case x:t= CSR_ ## x ; break
925 e(75);e(150);e(300);e(600);e(1200);e(2400);e(4800);
927 e(19200);e(57600);e(38400);
928 /* TA supports 110, but not 115200, MTA supports 115200, but not 110 */
930 if (port
->board
->ta_type
== MOD_TA
) {
935 printk (KERN_INFO
"sx: Unsupported baud rate: %d.\n", port
->gs
.baud
);
939 if (port
->board
->ta_type
== MOD_TA
) {
941 printk (KERN_INFO
"sx: Unsupported baud rate: %d.\n", port
->gs
.baud
);
951 printk (KERN_INFO
"sx: Unsupported baud rate: %d.\n", port
->gs
.baud
);
956 sx_setsignals (port
, 1, -1);
957 sx_write_channel_byte (port
, hi_csr
, t
* 0x11);
959 sx_setsignals (port
, 0, -1);
965 /* Simon Allen's version of this routine was 225 lines long. 85 is a lot
968 static void sx_set_real_termios (void *ptr
)
970 struct sx_port
*port
= ptr
;
974 /* What is this doing here? -- REW
975 Ha! figured it out. It is to allow you to get DTR active again
976 if you've dropped it with stty 0. Moved to set_baud, where it
977 belongs (next to the drop dtr if baud == 0) -- REW */
978 /* sx_setsignals (port, 1, -1); */
982 #define CFLAG port->gs.tty->termios->c_cflag
983 sx_write_channel_byte (port
, hi_mr1
,
984 (C_PARENB (port
->gs
.tty
)? MR1_WITH
:MR1_NONE
) |
985 (C_PARODD (port
->gs
.tty
)? MR1_ODD
:MR1_EVEN
) |
986 (C_CRTSCTS(port
->gs
.tty
)? MR1_RTS_RXFLOW
:0) |
987 (((CFLAG
& CSIZE
)==CS8
) ? MR1_8_BITS
:0) |
988 (((CFLAG
& CSIZE
)==CS7
) ? MR1_7_BITS
:0) |
989 (((CFLAG
& CSIZE
)==CS6
) ? MR1_6_BITS
:0) |
990 (((CFLAG
& CSIZE
)==CS5
) ? MR1_5_BITS
:0) );
992 sx_write_channel_byte (port
, hi_mr2
,
993 (C_CRTSCTS(port
->gs
.tty
)?MR2_CTS_TXFLOW
:0) |
994 (C_CSTOPB (port
->gs
.tty
)?MR2_2_STOP
:MR2_1_STOP
));
996 switch (CFLAG
& CSIZE
) {
997 case CS8
:sx_write_channel_byte (port
, hi_mask
, 0xff);break;
998 case CS7
:sx_write_channel_byte (port
, hi_mask
, 0x7f);break;
999 case CS6
:sx_write_channel_byte (port
, hi_mask
, 0x3f);break;
1000 case CS5
:sx_write_channel_byte (port
, hi_mask
, 0x1f);break;
1002 printk (KERN_INFO
"sx: Invalid wordsize: %d\n", CFLAG
& CSIZE
);
1006 sx_write_channel_byte (port
, hi_prtcl
,
1007 (I_IXON (port
->gs
.tty
)?SP_TXEN
:0) |
1008 (I_IXOFF (port
->gs
.tty
)?SP_RXEN
:0) |
1009 (I_IXANY (port
->gs
.tty
)?SP_TANY
:0) |
1012 sx_write_channel_byte (port
, hi_break
,
1013 I_OTHER(port
->gs
.tty
) ? 0:
1014 (I_IGNBRK(port
->gs
.tty
)?BR_IGN
:0 |
1015 I_BRKINT(port
->gs
.tty
)?BR_INT
:0));
1017 sx_write_channel_byte (port
, hi_txon
, START_CHAR (port
->gs
.tty
));
1018 sx_write_channel_byte (port
, hi_rxon
, START_CHAR (port
->gs
.tty
));
1019 sx_write_channel_byte (port
, hi_txoff
, STOP_CHAR (port
->gs
.tty
));
1020 sx_write_channel_byte (port
, hi_rxoff
, STOP_CHAR (port
->gs
.tty
));
1022 if (sx_read_channel_byte (port
, hi_hstat
) == HS_IDLE_OPEN
) {
1023 if (sx_send_command (port
, HS_CONFIG
, -1, HS_IDLE_OPEN
) != 1) {
1024 printk (KERN_WARNING
"sx: Sent reconfigure command, but card didn't react.\n");
1027 sx_dprintk (SX_DEBUG_TERMIOS
,
1028 "sx: Not sending reconfigure: port isn't open (%02x).\n",
1029 sx_read_channel_byte (port
, hi_hstat
));
1033 /* Tell line discipline whether we will do input cooking */
1034 if(I_OTHER(port
->gs
.tty
)) {
1035 clear_bit(TTY_HW_COOK_IN
, &port
->gs
.tty
->flags
);
1037 set_bit(TTY_HW_COOK_IN
, &port
->gs
.tty
->flags
);
1039 sx_dprintk (SX_DEBUG_TERMIOS
, "iflags: %x(%d) ",
1040 port
->gs
.tty
->termios
->c_iflag
,
1041 I_OTHER(port
->gs
.tty
));
1044 /* Tell line discipline whether we will do output cooking.
1045 * If OPOST is set and no other output flags are set then we can do output
1046 * processing. Even if only *one* other flag in the O_OTHER group is set
1047 * we do cooking in software.
1049 if(O_OPOST(port
->gs
.tty
) && !O_OTHER(port
->gs
.tty
)) {
1050 set_bit(TTY_HW_COOK_OUT
, &port
->gs
.tty
->flags
);
1052 clear_bit(TTY_HW_COOK_OUT
, &port
->gs
.tty
->flags
);
1054 sx_dprintk (SX_DEBUG_TERMIOS
, "oflags: %x(%d)\n",
1055 port
->gs
.tty
->termios
->c_oflag
,
1056 O_OTHER(port
->gs
.tty
));
1057 /* port->c_dcd = sx_get_CD (port); */
1063 /* ********************************************************************** *
1064 * the interrupt related routines *
1065 * ********************************************************************** */
1068 Other drivers use the macro "MIN" to calculate how much to copy.
1069 This has the disadvantage that it will evaluate parts twice. That's
1070 expensive when it's IO (and the compiler cannot optimize those away!).
1071 Moreover, I'm not sure that you're race-free.
1073 I assign a value, and then only allow the value to decrease. This
1074 is always safe. This makes the code a few lines longer, and you
1075 know I'm dead against that, but I think it is required in this
1079 void sx_transmit_chars (struct sx_port
*port
)
1086 sx_dprintk (SX_DEBUG_TRANSMIT
, "Port %p: transmit %d chars\n",
1087 port
, port
->gs
.xmit_cnt
);
1089 if (test_and_set_bit (SX_PORT_TRANSMIT_LOCK
, &port
->locks
)) {
1094 c
= port
->gs
.xmit_cnt
;
1096 sx_dprintk (SX_DEBUG_TRANSMIT
, "Copying %d ", c
);
1097 tx_ip
= sx_read_channel_byte (port
, hi_txipos
);
1099 /* Took me 5 minutes to deduce this formula.
1100 Luckily it is literally in the manual in section 6.5.4.3.5 */
1101 txroom
= (sx_read_channel_byte (port
, hi_txopos
) - tx_ip
- 1) & 0xff;
1103 /* Don't copy more bytes than there is room for in the buffer */
1106 sx_dprintk (SX_DEBUG_TRANSMIT
, " %d(%d) ", c
, txroom
);
1108 /* Don't copy past the end of the hardware transmit buffer */
1109 if (c
> 0x100 - tx_ip
)
1112 sx_dprintk (SX_DEBUG_TRANSMIT
, " %d(%d) ", c
, 0x100-tx_ip
);
1114 /* Don't copy pas the end of the source buffer */
1115 if (c
> SERIAL_XMIT_SIZE
- port
->gs
.xmit_tail
)
1116 c
= SERIAL_XMIT_SIZE
- port
->gs
.xmit_tail
;
1118 sx_dprintk (SX_DEBUG_TRANSMIT
, " %d(%d) \n",
1119 c
, SERIAL_XMIT_SIZE
- port
->gs
.xmit_tail
);
1121 /* If for one reason or another, we can't copy more data, we're done! */
1125 memcpy_toio (port
->board
->base
+ CHAN_OFFSET(port
,hi_txbuf
) + tx_ip
,
1126 port
->gs
.xmit_buf
+ port
->gs
.xmit_tail
, c
);
1128 /* Update the pointer in the card */
1129 sx_write_channel_byte (port
, hi_txipos
, (tx_ip
+c
) & 0xff);
1131 /* Update the kernel buffer end */
1132 port
->gs
.xmit_tail
= (port
->gs
.xmit_tail
+ c
) & (SERIAL_XMIT_SIZE
-1);
1134 /* This one last. (this is essential)
1135 It would allow others to start putting more data into the buffer! */
1136 port
->gs
.xmit_cnt
-= c
;
1139 if (port
->gs
.xmit_cnt
== 0) {
1140 sx_disable_tx_interrupts (port
);
1143 if (port
->gs
.xmit_cnt
<= port
->gs
.wakeup_chars
) {
1144 if ((port
->gs
.tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1145 port
->gs
.tty
->ldisc
.write_wakeup
)
1146 (port
->gs
.tty
->ldisc
.write_wakeup
)(port
->gs
.tty
);
1147 sx_dprintk (SX_DEBUG_TRANSMIT
, "Waking up.... ldisc (%d)....\n",
1148 port
->gs
.wakeup_chars
);
1149 wake_up_interruptible(&port
->gs
.tty
->write_wait
);
1152 clear_bit (SX_PORT_TRANSMIT_LOCK
, &port
->locks
);
1157 /* Note the symmetry between receiving chars and transmitting them!
1158 Note: The kernel should have implemented both a receive buffer and
1159 a transmit buffer. */
1161 /* Inlined: Called only once. Remove the inline when you add another call */
1162 inline void sx_receive_chars (struct sx_port
*port
)
1166 struct tty_struct
*tty
;
1169 /* func_enter2 (); */
1172 rx_op
= sx_read_channel_byte (port
, hi_rxopos
);
1173 c
= (sx_read_channel_byte (port
, hi_rxipos
) - rx_op
) & 0xff;
1175 sx_dprintk (SX_DEBUG_RECEIVE
, "rxop=%d, c = %d.\n", rx_op
, c
);
1177 /* Don't copy more bytes than there is room for in the buffer */
1178 if (tty
->flip
.count
+ c
> TTY_FLIPBUF_SIZE
)
1179 c
= TTY_FLIPBUF_SIZE
- tty
->flip
.count
;
1181 sx_dprintk (SX_DEBUG_RECEIVE
, "c = %d.\n", c
);
1183 /* Don't copy past the end of the hardware receive buffer */
1184 if (rx_op
+ c
> 0x100) c
= 0x100 - rx_op
;
1186 sx_dprintk (SX_DEBUG_RECEIVE
, "c = %d.\n", c
);
1188 /* If for one reason or another, we can't copy more data, we're done! */
1191 sx_dprintk (SX_DEBUG_RECEIVE
, "Copying over %d chars. First is %d at %lx\n", c
,
1192 read_sx_byte (port
->board
, CHAN_OFFSET(port
,hi_rxbuf
) + rx_op
),
1193 CHAN_OFFSET(port
, hi_rxbuf
));
1194 memcpy_fromio (tty
->flip
.char_buf_ptr
,
1195 port
->board
->base
+ CHAN_OFFSET(port
,hi_rxbuf
) + rx_op
, c
);
1196 memset(tty
->flip
.flag_buf_ptr
, TTY_NORMAL
, c
);
1198 /* Update the kernel buffer end */
1199 tty
->flip
.count
+= c
;
1200 tty
->flip
.char_buf_ptr
+= c
;
1201 tty
->flip
.flag_buf_ptr
+= c
;
1203 /* This one last. ( Not essential.)
1204 It allows the card to start putting more data into the buffer!
1205 Update the pointer in the card */
1206 sx_write_channel_byte (port
, hi_rxopos
, (rx_op
+ c
) & 0xff);
1213 do_gettimeofday (&tv
);
1214 sx_dprintk (SX_DEBUG_RECEIVE
,
1215 "pushing flipq port %d (%3d chars): %d.%06d (%d/%d)\n",
1217 (int) (tv
.tv_sec
% 60), (int)tv
.tv_usec
, tty
->raw
, tty
->real_raw
);
1219 /* Tell the rest of the system the news. Great news. New characters! */
1220 tty_flip_buffer_push (tty
);
1221 /* tty_schedule_flip (tty); */
1227 /* Inlined: it is called only once. Remove the inline if you add another
1229 inline void sx_check_modem_signals (struct sx_port
*port
)
1234 hi_state
= sx_read_channel_byte (port
, hi_state
);
1235 sx_dprintk (SX_DEBUG_MODEMSIGNALS
, "Checking modem signals (%d/%d)\n",
1236 port
->c_dcd
, sx_get_CD (port
));
1238 if (hi_state
& ST_BREAK
) {
1239 hi_state
&= ~ST_BREAK
;
1240 sx_dprintk (SX_DEBUG_MODEMSIGNALS
, "got a break.\n");
1242 sx_write_channel_byte (port
, hi_state
, hi_state
);
1243 if (port
->gs
.flags
& ASYNC_SAK
) {
1244 do_SAK (port
->gs
.tty
);
1247 if (hi_state
& ST_DCD
) {
1248 hi_state
&= ~ST_DCD
;
1249 sx_dprintk (SX_DEBUG_MODEMSIGNALS
, "got a DCD change.\n");
1250 sx_write_channel_byte (port
, hi_state
, hi_state
);
1251 c_dcd
= sx_get_CD (port
);
1252 sx_dprintk (SX_DEBUG_MODEMSIGNALS
, "DCD is now %d\n", c_dcd
);
1253 if (c_dcd
!= port
->c_dcd
) {
1254 port
->c_dcd
= c_dcd
;
1255 if (sx_get_CD (port
)) {
1257 if( (~(port
->gs
.flags
& ASYNC_NORMAL_ACTIVE
) ||
1258 ~(port
->gs
.flags
& ASYNC_CALLOUT_ACTIVE
)) &&
1259 (sx_read_channel_byte(port
, hi_hstat
) != HS_IDLE_CLOSED
)) {
1260 /* Are we blocking in open?*/
1261 sx_dprintk (SX_DEBUG_MODEMSIGNALS
, "DCD active, unblocking open\n");
1262 wake_up_interruptible(&port
->gs
.open_wait
);
1264 sx_dprintk (SX_DEBUG_MODEMSIGNALS
, "DCD raised. Ignoring.\n");
1267 /* DCD went down! */
1268 if (!((port
->gs
.flags
& ASYNC_CALLOUT_ACTIVE
) &&
1269 (port
->gs
.flags
& ASYNC_CALLOUT_NOHUP
))) {
1270 sx_dprintk (SX_DEBUG_MODEMSIGNALS
, "DCD dropped. hanging up....\n");
1271 tty_hangup (port
->gs
.tty
);
1273 sx_dprintk (SX_DEBUG_MODEMSIGNALS
, "DCD dropped. ignoring.\n");
1277 sx_dprintk (SX_DEBUG_MODEMSIGNALS
, "Hmmm. card told us DCD changed, but it didn't.\n");
1283 /* This is what an interrupt routine should look like.
1284 * Small, elegant, clear.
1287 static void sx_interrupt (int irq
, void *ptr
, struct pt_regs
*regs
)
1289 struct sx_board
*board
= ptr
;
1290 struct sx_port
*port
;
1293 /* func_enter (); */
1294 sx_dprintk (SX_DEBUG_FLOW
, "sx: enter sx_interrupt (%d/%d)\n", irq
, board
->irq
);
1296 /* AAargh! The order in which to do these things is essential and
1299 - Rate limit goes before "recursive". Otherwise a series of
1300 recursive calls will hang the machine in the interrupt routine.
1302 - hardware twiddling goes before "recursive". Otherwise when we
1303 poll the card, and a recursive interrupt happens, we wont
1304 ack the card, so it might keep on interrupting us. (especially
1305 level sensitive interrupt systems like PCI).
1307 - Rate limit goes before hardware twiddling. Otherwise we won't
1308 catch a card that has gone bonkers.
1310 - The "initialized" test goes after the hardware twiddling. Otherwise
1311 the card will stick us in the interrupt routine again.
1313 - The initialized test goes before recursive.
1318 #ifdef IRQ_RATE_LIMIT
1319 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
1320 actual interrupt routine!. (Well, used to when I wrote that comment) */
1325 if (lastjif
== jiffies
) {
1326 if (++nintr
> IRQ_RATE_LIMIT
) {
1327 free_irq (board
->irq
, board
);
1328 printk (KERN_ERR
"sx: Too many interrupts. Turning off interrupt %d.\n",
1339 if (board
->irq
== irq
) {
1340 /* Tell the card we've noticed the interrupt. */
1342 sx_write_board_word (board
, cc_int_pending
, 0);
1343 if (IS_SX_BOARD (board
)) {
1344 write_sx_byte (board
, SX_RESET_IRQ
, 1);
1346 write_sx_byte (board
, SI2_ISA_INTCLEAR
, SI2_ISA_INTCLEAR_CLEAR
);
1347 write_sx_byte (board
, SI2_ISA_INTCLEAR
, SI2_ISA_INTCLEAR_SET
);
1351 if (!sx_initialized
) return;
1352 if (!(board
->flags
& SX_BOARD_INITIALIZED
)) return;
1354 if (test_and_set_bit (SX_BOARD_INTR_LOCK
, &board
->locks
)) {
1355 printk (KERN_ERR
"Recursive interrupt! (%d)\n", board
->irq
);
1359 for (i
=0;i
<board
->nports
;i
++) {
1360 port
= &board
->ports
[i
];
1361 if (port
->gs
.flags
& GS_ACTIVE
) {
1362 if (sx_read_channel_byte (port
, hi_state
)) {
1363 sx_dprintk (SX_DEBUG_INTERRUPTS
,
1364 "Port %d: modem signal change?... \n", i
);
1365 sx_check_modem_signals (port
);
1367 if (port
->gs
.xmit_cnt
) {
1368 sx_transmit_chars (port
);
1370 if (!(port
->gs
.flags
& SX_RX_THROTTLE
)) {
1371 sx_receive_chars (port
);
1376 clear_bit (SX_BOARD_INTR_LOCK
, &board
->locks
);
1378 sx_dprintk (SX_DEBUG_FLOW
, "sx: exit sx_interrupt (%d/%d)\n", irq
, board
->irq
);
1383 static void sx_pollfunc (unsigned long data
)
1385 struct sx_board
*board
= (struct sx_board
*) data
;
1389 sx_interrupt (0, board
, NULL
);
1391 board
->timer
.expires
= jiffies
+ sx_poll
;
1392 add_timer (&board
->timer
);
1398 /* ********************************************************************** *
1399 * Here are the routines that actually *
1400 * interface with the generic_serial driver *
1401 * ********************************************************************** */
1403 /* Ehhm. I don't know how to fiddle with interrupts on the SX card. --REW */
1404 /* Hmm. Ok I figured it out. You don't. */
1406 static void sx_disable_tx_interrupts (void * ptr
)
1408 struct sx_port
*port
= ptr
;
1411 port
->gs
.flags
&= ~GS_TX_INTEN
;
1417 static void sx_enable_tx_interrupts (void * ptr
)
1419 struct sx_port
*port
= ptr
;
1423 /* First transmit the characters that we're supposed to */
1424 sx_transmit_chars (port
);
1426 /* The sx card will never interrupt us if we don't fill the buffer
1427 past 25%. So we keep considering interrupts off if that's the case. */
1428 data_in_buffer
= (sx_read_channel_byte (port
, hi_txipos
) -
1429 sx_read_channel_byte (port
, hi_txopos
)) & 0xff;
1431 /* XXX Must be "HIGH_WATER" for SI card according to doc. */
1432 if (data_in_buffer
< LOW_WATER
)
1433 port
->gs
.flags
&= ~GS_TX_INTEN
;
1439 static void sx_disable_rx_interrupts (void * ptr
)
1441 /* struct sx_port *port = ptr; */
1447 static void sx_enable_rx_interrupts (void * ptr
)
1449 /* struct sx_port *port = ptr; */
1456 /* Jeez. Isn't this simple? */
1457 static int sx_get_CD (void * ptr
)
1459 struct sx_port
*port
= ptr
;
1463 return ((sx_read_channel_byte (port
, hi_ip
) & IP_DCD
) != 0);
1467 /* Jeez. Isn't this simple? */
1468 static int sx_chars_in_buffer (void * ptr
)
1470 struct sx_port
*port
= ptr
;
1474 return ((sx_read_channel_byte (port
, hi_txipos
) -
1475 sx_read_channel_byte (port
, hi_txopos
)) & 0xff);
1479 static void sx_shutdown_port (void * ptr
)
1481 struct sx_port
*port
= ptr
;
1485 port
->gs
.flags
&= ~ GS_ACTIVE
;
1486 if (port
->gs
.tty
&& port
->gs
.tty
->termios
->c_cflag
& HUPCL
) {
1487 sx_setsignals (port
, 0, 0);
1497 /* ********************************************************************** *
1498 * Here are the routines that actually *
1499 * interface with the rest of the system *
1500 * ********************************************************************** */
1503 static int sx_fw_open(struct inode
*inode
, struct file
*filp
)
1512 static INT
sx_fw_release(struct inode
*inode
, struct file
*filp
)
1521 static int sx_open (struct tty_struct
* tty
, struct file
* filp
)
1523 struct sx_port
*port
;
1528 if (!sx_initialized
) {
1532 line
= MINOR(tty
->device
);
1533 sx_dprintk (SX_DEBUG_OPEN
, "%d: opening line %d. tty=%p ctty=%p, np=%d)\n",
1534 current
->pid
, line
, tty
, current
->tty
, sx_nports
);
1536 if ((line
< 0) || (line
>= SX_NPORTS
) || (line
>= sx_nports
))
1539 port
= & sx_ports
[line
];
1540 port
->c_dcd
= 0; /* Make sure that the first interrupt doesn't detect a
1541 1 -> 0 transition. */
1544 sx_dprintk (SX_DEBUG_OPEN
, "port = %p c_dcd = %d\n", port
, port
->c_dcd
);
1546 tty
->driver_data
= port
;
1550 sx_dprintk (SX_DEBUG_OPEN
, "starting port\n");
1553 * Start up serial port
1555 retval
= gs_init_port(&port
->gs
);
1556 sx_dprintk (SX_DEBUG_OPEN
, "done gs_init\n");
1562 port
->gs
.flags
|= GS_ACTIVE
;
1563 sx_setsignals (port
, 1,1);
1565 sx_dprintk (SX_DEBUG_OPEN
, "before inc_use_count (count=%d.\n",
1567 if (port
->gs
.count
== 1) {
1570 sx_dprintk (SX_DEBUG_OPEN
, "after inc_use_count\n");
1573 if (sx_debug
& SX_DEBUG_OPEN
)
1574 my_hd ((unsigned char *)port
, sizeof (*port
));
1576 if (sx_debug
& SX_DEBUG_OPEN
)
1577 my_hd ((unsigned char *)port
->board
->base
+ port
->ch_base
,
1581 if (sx_send_command (port
, HS_LOPEN
, -1, HS_IDLE_OPEN
) != 1) {
1582 printk (KERN_ERR
"sx: Card didn't respond to LOPEN command.\n");
1588 retval
= block_til_ready(port
, filp
);
1589 sx_dprintk (SX_DEBUG_OPEN
, "Block til ready returned %d. Count=%d\n",
1590 retval
, port
->gs
.count
);
1597 /* tty->low_latency = 1; */
1599 if ((port
->gs
.count
== 1) && (port
->gs
.flags
& ASYNC_SPLIT_TERMIOS
)) {
1600 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
1601 *tty
->termios
= port
->gs
.normal_termios
;
1603 *tty
->termios
= port
->gs
.callout_termios
;
1604 sx_set_real_termios (port
);
1607 port
->gs
.session
= current
->session
;
1608 port
->gs
.pgrp
= current
->pgrp
;
1609 port
->c_dcd
= sx_get_CD (port
);
1610 sx_dprintk (SX_DEBUG_OPEN
, "at open: cd=%d\n", port
->c_dcd
);
1617 /* I haven't the foggiest why the decrement use count has to happen
1618 here. The whole linux serial drivers stuff needs to be redesigned.
1619 My guess is that this is a hack to minimize the impact of a bug
1620 elsewhere. Thinking about it some more. (try it sometime) Try
1621 running minicom on a serial port that is driven by a modularized
1622 driver. Have the modem hangup. Then remove the driver module. Then
1623 exit minicom. I expect an "oops". -- REW */
1624 static void sx_hungup (void *ptr
)
1632 static void sx_close (void *ptr
)
1634 struct sx_port
*port
= ptr
;
1635 /* Give the port 5 seconds to close down. */
1639 sx_send_command (port
, HS_CLOSE
, 0, 0);
1641 while (to
-- && (sx_read_channel_byte (port
, hi_hstat
) != HS_IDLE_CLOSED
)) {
1642 current
->state
= TASK_INTERRUPTIBLE
;
1643 schedule_timeout (1);
1644 if (signal_pending (current
))
1647 current
->state
= TASK_RUNNING
;
1648 if (sx_read_channel_byte (port
, hi_hstat
) != HS_IDLE_CLOSED
) {
1649 if (sx_send_command (port
, HS_FORCE_CLOSED
, -1, HS_IDLE_CLOSED
) != 1) {
1651 "sx: sent the force_close command, but card didn't react\n");
1653 sx_dprintk (SX_DEBUG_CLOSE
, "sent the force_close command.\n");
1656 sx_dprintk (SX_DEBUG_CLOSE
, "waited %d jiffies for close. count=%d\n",
1657 5 * HZ
- to
- 1, port
->gs
.count
);
1665 /* This is relatively thorough. But then again it is only 20 lines. */
1666 #define MARCHUP for (i=min;i<max;i++)
1667 #define MARCHDOWN for (i=max-1;i>=min;i--)
1668 #define W0 write_sx_byte (board, i, 0x55)
1669 #define W1 write_sx_byte (board, i, 0xaa)
1670 #define R0 if (read_sx_byte (board, i) != 0x55) return 1
1671 #define R1 if (read_sx_byte (board, i) != 0xaa) return 1
1673 /* This memtest takes a human-noticable time. You normally only do it
1674 once a boot, so I guess that it is worth it. */
1675 int do_memtest (struct sx_board
*board
, int min
, int max
)
1679 /* This is a marchb. Theoretically, marchb catches much more than
1680 simpler tests. In practise, the longer test just catches more
1681 intermittent errors. -- REW
1682 (For the theory behind memory testing see:
1683 Testing Semiconductor Memories by A.J. van de Goor.) */
1685 MARCHUP
{R0
;W1
;R1
;W0
;R0
;W1
;}
1687 MARCHDOWN
{R1
;W0
;W1
;W0
;}
1688 MARCHDOWN
{R0
;W1
;W0
;}
1701 #define MARCHUP for (i=min;i<max;i+=2)
1702 #define MARCHDOWN for (i=max-1;i>=min;i-=2)
1703 #define W0 write_sx_word (board, i, 0x55aa)
1704 #define W1 write_sx_word (board, i, 0xaa55)
1705 #define R0 if (read_sx_word (board, i) != 0x55aa) return 1
1706 #define R1 if (read_sx_word (board, i) != 0xaa55) return 1
1708 /* This memtest takes a human-noticable time. You normally only do it
1709 once a boot, so I guess that it is worth it. */
1710 int do_memtest_w (struct sx_board
*board
, int min
, int max
)
1715 MARCHUP
{R0
;W1
;R1
;W0
;R0
;W1
;}
1717 MARCHDOWN
{R1
;W0
;W1
;W0
;}
1718 MARCHDOWN
{R0
;W1
;W0
;}
1724 static int sx_fw_ioctl (struct inode
*inode
, struct file
*filp
,
1725 unsigned int cmd
, unsigned long arg
)
1728 int *descr
= (int *)arg
, i
;
1729 static struct sx_board
*board
= NULL
;
1730 int nbytes
, offset
, data
;
1736 /* Removed superuser check: Sysops can use the permissions on the device
1737 file to restrict access. Recommendation: Root only. (root.root 600) */
1743 sx_dprintk (SX_DEBUG_FIRMWARE
, "IOCTL %x: %lx\n", cmd
, arg
);
1745 if (!board
) board
= &boards
[0];
1746 if (board
->flags
& SX_BOARD_PRESENT
) {
1747 sx_dprintk (SX_DEBUG_FIRMWARE
, "Board present! (%x)\n",
1750 sx_dprintk (SX_DEBUG_FIRMWARE
, "Board not present! (%x) all:",
1752 for (i
=0;i
< SX_NBOARDS
;i
++)
1753 sx_dprintk (SX_DEBUG_FIRMWARE
, "<%x> ", boards
[i
].flags
);
1754 sx_dprintk (SX_DEBUG_FIRMWARE
, "\n");
1759 case SXIO_SET_BOARD
:
1760 sx_dprintk (SX_DEBUG_FIRMWARE
, "set board to %ld\n", arg
);
1761 if (arg
> SX_NBOARDS
) return -EIO
;
1762 sx_dprintk (SX_DEBUG_FIRMWARE
, "not out of range\n");
1763 if (!(boards
[arg
].flags
& SX_BOARD_PRESENT
)) return -EIO
;
1764 sx_dprintk (SX_DEBUG_FIRMWARE
, ".. and present!\n");
1765 board
= &boards
[arg
];
1768 rc
= IS_SX_BOARD (board
)? SX_TYPE_SX
:SX_TYPE_SI
;
1769 sx_dprintk (SX_DEBUG_FIRMWARE
, "returning type= %d\n", rc
);
1771 case SXIO_DO_RAMTEST
:
1772 if (sx_initialized
) /* Already initialized: better not ramtest the board. */
1774 if (IS_SX_BOARD (board
)) {
1775 rc
= do_memtest (board
, 0, 0x7000);
1776 if (!rc
) rc
= do_memtest (board
, 0, 0x7000);
1777 /*if (!rc) rc = do_memtest_w (board, 0, 0x7000);*/
1779 rc
= do_memtest (board
, 0, 0x7ff8);
1780 /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */
1782 sx_dprintk (SX_DEBUG_FIRMWARE
, "returning memtest result= %d\n", rc
);
1785 if (sx_initialized
) /* Already initialized */
1787 if (!sx_reset (board
))
1789 sx_dprintk (SX_DEBUG_INIT
, "reset the board...\n");
1791 tmp
= kmalloc (SX_CHUNK_SIZE
, GFP_USER
);
1792 if (!tmp
) return -ENOMEM
;
1793 Get_user (nbytes
, descr
++);
1794 Get_user (offset
, descr
++);
1795 Get_user (data
, descr
++);
1796 while (nbytes
&& data
) {
1797 for (i
=0;i
<nbytes
;i
+= SX_CHUNK_SIZE
) {
1798 copy_from_user (tmp
, (char *)data
+i
,
1799 (i
+SX_CHUNK_SIZE
>nbytes
)?nbytes
-i
:SX_CHUNK_SIZE
);
1800 memcpy_toio ((char *) (board
->base
+ offset
+ i
), tmp
,
1801 (i
+SX_CHUNK_SIZE
>nbytes
)?nbytes
-i
:SX_CHUNK_SIZE
);
1804 Get_user (nbytes
, descr
++);
1805 Get_user (offset
, descr
++);
1806 Get_user (data
, descr
++);
1809 sx_nports
+= sx_init_board (board
);
1813 if (sx_initialized
) /* Already initialized */
1815 /* This is not allowed until all boards are initialized... */
1816 for (i
=0;i
<SX_NBOARDS
;i
++) {
1817 if ( (boards
[i
].flags
& SX_BOARD_PRESENT
) &&
1818 !(boards
[i
].flags
& SX_BOARD_INITIALIZED
))
1821 for (i
=0;i
<SX_NBOARDS
;i
++)
1822 if (!(boards
[i
].flags
& SX_BOARD_PRESENT
)) break;
1824 sx_dprintk (SX_DEBUG_FIRMWARE
, "initing portstructs, %d boards, "
1825 "%d channels, first board: %d ports\n",
1826 i
, sx_nports
, boards
[0].nports
);
1827 rc
= sx_init_portstructs (i
, sx_nports
);
1838 case SXIO_SETGSDEBUG
:
1841 case SXIO_GETGSDEBUG
:
1845 printk (KERN_WARNING
"Unknown ioctl on firmware device (%x).\n", cmd
);
1853 static int sx_ioctl (struct tty_struct
* tty
, struct file
* filp
,
1854 unsigned int cmd
, unsigned long arg
)
1857 struct sx_port
*port
= tty
->driver_data
;
1860 /* func_enter2(); */
1865 rc
= Put_user(((tty
->termios
->c_cflag
& CLOCAL
) ? 1 : 0),
1866 (unsigned int *) arg
);
1869 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
1870 sizeof(int))) == 0) {
1871 Get_user(ival
, (unsigned int *) arg
);
1872 tty
->termios
->c_cflag
=
1873 (tty
->termios
->c_cflag
& ~CLOCAL
) |
1874 (ival
? CLOCAL
: 0);
1878 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
1879 sizeof(struct serial_struct
))) == 0)
1880 gs_getserial(&port
->gs
, (struct serial_struct
*) arg
);
1883 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
1884 sizeof(struct serial_struct
))) == 0)
1885 rc
= gs_setserial(&port
->gs
, (struct serial_struct
*) arg
);
1888 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
1889 sizeof(unsigned int))) == 0) {
1890 ival
= sx_getsignals(port
);
1891 put_user(ival
, (unsigned int *) arg
);
1895 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
1896 sizeof(unsigned int))) == 0) {
1897 Get_user(ival
, (unsigned int *) arg
);
1898 sx_setsignals(port
, ((ival
& TIOCM_DTR
) ? 1 : -1),
1899 ((ival
& TIOCM_RTS
) ? 1 : -1));
1903 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
1904 sizeof(unsigned int))) == 0) {
1905 Get_user(ival
, (unsigned int *) arg
);
1906 sx_setsignals(port
, ((ival
& TIOCM_DTR
) ? 0 : -1),
1907 ((ival
& TIOCM_RTS
) ? 0 : -1));
1911 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
1912 sizeof(unsigned int))) == 0) {
1913 Get_user(ival
, (unsigned int *) arg
);
1914 sx_setsignals(port
, ((ival
& TIOCM_DTR
) ? 1 : 0),
1915 ((ival
& TIOCM_RTS
) ? 1 : 0));
1929 /* The throttle/unthrottle scheme for the Specialix card is different
1930 * from other drivers and deserves some explanation.
1931 * The Specialix hardware takes care of XON/XOFF
1932 * and CTS/RTS flow control itself. This means that all we have to
1933 * do when signalled by the upper tty layer to throttle/unthrottle is
1934 * to make a note of it here. When we come to read characters from the
1935 * rx buffers on the card (sx_receive_chars()) we look to see if the
1936 * upper layer can accept more (as noted here in sx_rx_throt[]).
1937 * If it can't we simply don't remove chars from the cards buffer.
1938 * When the tty layer can accept chars, we again note that here and when
1939 * sx_receive_chars() is called it will remove them from the cards buffer.
1940 * The card will notice that a ports buffer has drained below some low
1941 * water mark and will unflow control the line itself, using whatever
1942 * flow control scheme is in use for that port. -- Simon Allen
1945 static void sx_throttle (struct tty_struct
* tty
)
1947 struct sx_port
*port
= (struct sx_port
*)tty
->driver_data
;
1950 /* If the port is using any type of input flow
1951 * control then throttle the port.
1953 if((tty
->termios
->c_cflag
& CRTSCTS
) || (I_IXOFF(tty
)) ) {
1954 port
->gs
.flags
|= SX_RX_THROTTLE
;
1960 static void sx_unthrottle (struct tty_struct
* tty
)
1962 struct sx_port
*port
= (struct sx_port
*)tty
->driver_data
;
1965 /* Always unthrottle even if flow control is not enabled on
1966 * this port in case we disabled flow control while the port
1969 port
->gs
.flags
&= ~SX_RX_THROTTLE
;
1975 /* ********************************************************************** *
1976 * Here are the initialization routines. *
1977 * ********************************************************************** */
1982 static int sx_init_board (struct sx_board
*board
)
1990 /* This is preceded by downloading the download code. */
1992 board
->flags
|= SX_BOARD_INITIALIZED
;
1994 /* This resets the processor again, to make sure it didn't do any
1995 foolish things while we were downloading the image */
1996 if (!sx_reset (board
))
1999 sx_start_board (board
);
2001 if (!sx_busy_wait_neq (board
, 0, 0xff, 0)) {
2002 printk (KERN_ERR
"sx: Ooops. Board won't initialize.\n");
2006 /* Ok. So now the processor on the card is running. It gathered
2007 some info for us... */
2008 sx_dprintk (SX_DEBUG_INIT
, "The sxcard structure:\n");
2009 if (sx_debug
& SX_DEBUG_INIT
) my_hd ((char *)(board
->base
), 0x10);
2010 sx_dprintk (SX_DEBUG_INIT
, "the first sx_module structure:\n");
2011 if (sx_debug
& SX_DEBUG_INIT
) my_hd ((char *)(board
->base
+ 0x80), 0x30);
2013 sx_dprintk (SX_DEBUG_INIT
,
2014 "init_status: %x, %dk memory, firmware V%x.%02x,\n",
2015 read_sx_byte (board
, 0), read_sx_byte(board
, 1),
2016 read_sx_byte (board
, 5), read_sx_byte(board
, 4));
2018 if (read_sx_byte (board
, 0) == 0xff) {
2019 printk (KERN_INFO
"sx: No modules found. Sorry.\n");
2026 if (IS_SX_BOARD(board
)) {
2027 sx_write_board_word (board
, cc_int_count
, sx_maxints
);
2030 sx_write_board_word (board
, cc_int_count
, SI_PROCESSOR_CLOCK
/8/sx_maxints
);
2033 /* grab the first module type... */
2034 /* board->ta_type = mod_compat_type (read_sx_byte (board, 0x80 + 0x08)); */
2035 board
->ta_type
= mod_compat_type (sx_read_module_byte (board
, 0x80, mc_chip
));
2038 for (addr
= 0x80;addr
!= 0;addr
= read_sx_word (board
, addr
) & 0x7fff) {
2039 type
= sx_read_module_byte (board
, addr
, mc_chip
);
2040 sx_dprintk (SX_DEBUG_INIT
, "Module at %x: %d channels\n",
2041 addr
, read_sx_byte (board
, addr
+ 2));
2043 chans
+= sx_read_module_byte (board
, addr
, mc_type
);
2045 sx_dprintk (SX_DEBUG_INIT
, "module is an %s, which has %s/%s panels\n",
2047 pan_type_s (sx_read_module_byte (board
, addr
, mc_mods
) & 0xf),
2048 pan_type_s (sx_read_module_byte (board
, addr
, mc_mods
) >> 4));
2050 sx_dprintk (SX_DEBUG_INIT
, "CD1400 versions: %x/%x, ASIC version: %x\n",
2051 sx_read_module_byte (board
, addr
, mc_rev1
),
2052 sx_read_module_byte (board
, addr
, mc_rev2
),
2053 sx_read_module_byte (board
, addr
, mc_mtaasic_rev
));
2055 /* The following combinations are illegal: It should theoretically
2056 work, but timing problems make the bus HANG. */
2058 if (mod_compat_type (type
) != board
->ta_type
) {
2059 printk (KERN_ERR
"sx: This is an invalid configuration.\n"
2060 "Don't mix TA/MTA/SXDC on the same hostadapter.\n");
2064 if (IS_SI_BOARD(board
) && (mod_compat_type(type
) == 4)) {
2065 printk (KERN_ERR
"sx: This is an invalid configuration.\n"
2066 "Don't use SXDCs on an SI/XIO adapter.\n");
2070 #if 0 /* Problem fixed: firmware 3.05 */
2071 if (IS_SX_BOARD(board
) && (type
== TA8
)) {
2072 /* There are some issues with the firmware and the DCD/RTS
2073 lines. It might work if you tie them together or something.
2074 It might also work if you get a newer sx_firmware. Therefore
2075 this is just a warning. */
2076 printk (KERN_WARNING
"sx: The SX host doesn't work too well "
2077 "with the TA8 adapters.\nSpecialix is working on it.\n");
2083 /* board->flags |= SX_BOARD_PRESENT; */
2084 if(board
->irq
> 0) {
2085 /* fixed irq, probably PCI */
2086 if(sx_irqmask
& (1 << board
->irq
)) { /* may we use this irq? */
2087 if(request_irq(board
->irq
, sx_interrupt
, SA_SHIRQ
| SA_INTERRUPT
, "sx", board
)) {
2088 printk(KERN_ERR
"sx: Cannot allocate irq %d.\n", board
->irq
);
2093 } else if(board
->irq
< 0 && sx_irqmask
) {
2094 /* auto-allocate irq */
2096 int irqmask
= sx_irqmask
& (IS_SX_BOARD(board
) ? SX_ISA_IRQ_MASK
: SI2_ISA_IRQ_MASK
);
2097 for(irqnr
= 15; irqnr
> 0; irqnr
--)
2098 if(irqmask
& (1 << irqnr
))
2099 if(! request_irq(irqnr
, sx_interrupt
, SA_SHIRQ
| SA_INTERRUPT
, "sx", board
))
2102 printk(KERN_ERR
"sx: Cannot allocate IRQ.\n");
2108 /* Found a valid interrupt, start up interrupts! */
2109 sx_dprintk (SX_DEBUG_INIT
, "Using irq %d.\n", board
->irq
);
2110 sx_start_interrupts (board
);
2111 board
->poll
= sx_slowpoll
;
2112 board
->flags
|= SX_IRQ_ALLOCATED
;
2114 /* no irq: setup board for polled operation */
2115 board
->poll
= sx_poll
;
2116 sx_dprintk (SX_DEBUG_INIT
, "Using poll-interval %d.\n", board
->poll
);
2119 /* The timer should be initialized anyway: That way we can safely
2120 del_timer it when the module is unloaded. */
2121 init_timer (&board
->timer
);
2124 board
->timer
.data
= (unsigned long) board
;
2125 board
->timer
.function
= sx_pollfunc
;
2126 board
->timer
.expires
= jiffies
+ board
->poll
;
2127 add_timer (&board
->timer
);
2133 board
->nports
= chans
;
2134 sx_dprintk (SX_DEBUG_INIT
, "returning %d ports.", board
->nports
);
2141 void printheader(void)
2143 static int header_printed
= 0;
2145 if (!header_printed
) {
2146 printk (KERN_INFO
"Specialix SX driver "
2147 "(C) 1998/1999 R.E.Wolff@BitWizard.nl \n");
2148 printk (KERN_INFO
"sx: version %s\n", RCS_ID
);
2154 int probe_sx (struct sx_board
*board
)
2156 struct vpd_prom vpdp
;
2161 sx_dprintk (SX_DEBUG_PROBE
, "Going to verify vpd prom at %x.\n",
2162 board
->base
+ SX_VPD_ROM
);
2164 if (sx_debug
& SX_DEBUG_PROBE
)
2165 my_hd ((char *)(board
->base
+ SX_VPD_ROM
), 0x40);
2168 for (i
=0;i
< sizeof (struct vpd_prom
);i
++)
2169 *p
++ = read_sx_byte (board
, SX_VPD_ROM
+ i
*2);
2171 if (sx_debug
& SX_DEBUG_PROBE
)
2172 my_hd ((char *)&vpdp
, 0x20);
2174 sx_dprintk (SX_DEBUG_PROBE
, "checking identifier...\n");
2176 if (strncmp (vpdp
.identifier
, SX_VPD_IDENT_STRING
, 16) != 0) {
2177 sx_dprintk (SX_DEBUG_PROBE
, "Got non-SX identifier: '%s'\n",
2184 printk (KERN_DEBUG
"sx: Found an SX board at %x\n", board
->hw_base
);
2185 printk (KERN_DEBUG
"sx: hw_rev: %d, assembly level: %d, uniq ID:%08x, ",
2186 vpdp
.hwrev
, vpdp
.hwass
, vpdp
.uniqid
);
2187 printk ( "Manufactured: %d/%d\n",
2188 1970 + vpdp
.myear
, vpdp
.mweek
);
2191 if ((((vpdp
.uniqid
>> 24) & SX_UNIQUEID_MASK
) != SX_PCI_UNIQUEID1
) &&
2192 (((vpdp
.uniqid
>> 24) & SX_UNIQUEID_MASK
) != SX_ISA_UNIQUEID1
)) {
2193 /* This might be a bit harsh. This was the primary reason the
2194 SX/ISA card didn't work at first... */
2195 printk (KERN_ERR
"sx: Hmm. Not an SX/PCI or SX/ISA card. Sorry: giving up.\n");
2199 if (((vpdp
.uniqid
>> 24) & SX_UNIQUEID_MASK
) == SX_ISA_UNIQUEID1
) {
2200 if (board
->base
& 0x8000) {
2201 printk (KERN_WARNING
"sx: Warning: There may be hardware problems with the card at %x.\n", board
->base
);
2202 printk (KERN_WARNING
"sx: Read sx.txt for more info.\n");
2209 /* This resets the processor, and keeps it off the bus. */
2210 if (!sx_reset (board
))
2212 sx_dprintk (SX_DEBUG_INIT
, "reset the board...\n");
2214 board
->flags
|= SX_BOARD_PRESENT
;
2222 /* Specialix probes for this card at 32k increments from 640k to 16M.
2223 I consider machines with less than 16M unlikely nowadays, so I'm
2224 not probing above 1Mb. Also, 0xa0000, 0xb0000, are taken by the VGA
2225 card. 0xe0000 and 0xf0000 are taken by the BIOS. That only leaves
2226 0xc0000, 0xc8000, 0xd0000 and 0xd8000 . */
2228 int probe_si (struct sx_board
*board
)
2233 sx_dprintk (SX_DEBUG_PROBE
, "Going to verify SI signature %x.\n",
2234 board
->base
+ SI2_ISA_ID_BASE
);
2236 if (sx_debug
& SX_DEBUG_PROBE
)
2237 my_hd ((char *)(board
->base
+ SI2_ISA_ID_BASE
), 0x8);
2240 if ((read_sx_byte (board
, SI2_ISA_ID_BASE
+7-i
) & 7) != i
) {
2247 printk (KERN_DEBUG
"sx: Found an SI board at %x\n", board
->hw_base
);
2248 /* Compared to the SX boards, it is a complete guess as to what
2249 this card is up to... */
2253 /* This resets the processor, and keeps it off the bus. */
2254 if (!sx_reset (board
))
2256 sx_dprintk (SX_DEBUG_INIT
, "reset the board...\n");
2258 board
->flags
|= SX_BOARD_PRESENT
;
2265 static int sx_init_drivers(void)
2271 memset(&sx_driver
, 0, sizeof(sx_driver
));
2272 sx_driver
.magic
= TTY_DRIVER_MAGIC
;
2273 sx_driver
.driver_name
= "specialix_sx";
2274 sx_driver
.name
= "ttyX";
2275 sx_driver
.major
= SX_NORMAL_MAJOR
;
2276 sx_driver
.num
= sx_nports
;
2277 sx_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
2278 sx_driver
.subtype
= SX_TYPE_NORMAL
;
2279 sx_driver
.init_termios
= tty_std_termios
;
2280 sx_driver
.init_termios
.c_cflag
=
2281 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
2282 sx_driver
.flags
= TTY_DRIVER_REAL_RAW
;
2283 sx_driver
.refcount
= &sx_refcount
;
2284 sx_driver
.table
= sx_table
;
2285 sx_driver
.termios
= sx_termios
;
2286 sx_driver
.termios_locked
= sx_termios_locked
;
2288 sx_driver
.open
= sx_open
;
2289 sx_driver
.close
= gs_close
;
2290 sx_driver
.write
= gs_write
;
2291 sx_driver
.put_char
= gs_put_char
;
2292 sx_driver
.flush_chars
= gs_flush_chars
;
2293 sx_driver
.write_room
= gs_write_room
;
2294 sx_driver
.chars_in_buffer
= gs_chars_in_buffer
;
2295 sx_driver
.flush_buffer
= gs_flush_buffer
;
2296 sx_driver
.ioctl
= sx_ioctl
;
2297 sx_driver
.throttle
= sx_throttle
;
2298 sx_driver
.unthrottle
= sx_unthrottle
;
2299 sx_driver
.set_termios
= gs_set_termios
;
2300 sx_driver
.stop
= gs_stop
;
2301 sx_driver
.start
= gs_start
;
2302 sx_driver
.hangup
= gs_hangup
;
2304 sx_callout_driver
= sx_driver
;
2305 sx_callout_driver
.name
= "cux";
2306 sx_callout_driver
.major
= SX_CALLOUT_MAJOR
;
2307 sx_callout_driver
.subtype
= SX_TYPE_CALLOUT
;
2309 if ((error
= tty_register_driver(&sx_driver
))) {
2310 printk(KERN_ERR
"sx: Couldn't register sx driver, error = %d\n",
2314 if ((error
= tty_register_driver(&sx_callout_driver
))) {
2315 tty_unregister_driver(&sx_driver
);
2316 printk(KERN_ERR
"sx: Couldn't register sx callout driver, error = %d\n",
2326 void * ckmalloc (int size
)
2330 p
= kmalloc(size
, GFP_KERNEL
);
2337 static int sx_init_portstructs (int nboards
, int nports
)
2339 struct sx_board
*board
;
2340 struct sx_port
*port
;
2347 /* Many drivers statically allocate the maximum number of ports
2348 There is no reason not to allocate them dynamically. Is there? -- REW */
2349 sx_ports
= ckmalloc(nports
* sizeof (struct sx_port
));
2353 sx_termios
= ckmalloc(nports
* sizeof (struct termios
*));
2359 sx_termios_locked
= ckmalloc(nports
* sizeof (struct termios
*));
2360 if (!sx_termios_locked
) {
2366 /* Adjust the values in the "driver" */
2367 sx_driver
.termios
= sx_termios
;
2368 sx_driver
.termios_locked
= sx_termios_locked
;
2371 for (i
= 0; i
< nboards
; i
++) {
2373 board
->ports
= port
;
2374 for (j
=0; j
< boards
[i
].nports
;j
++) {
2375 sx_dprintk (SX_DEBUG_INIT
, "initing port %d\n", j
);
2376 port
->gs
.callout_termios
= tty_std_termios
;
2377 port
->gs
.normal_termios
= tty_std_termios
;
2378 port
->gs
.magic
= SX_MAGIC
;
2379 port
->gs
.close_delay
= HZ
/2;
2380 port
->gs
.closing_wait
= 30 * HZ
;
2381 port
->board
= board
;
2382 port
->gs
.rd
= &sx_real_driver
;
2383 #ifdef NEW_WRITE_LOCKING
2384 port
->gs
.port_write_sem
= MUTEX
;
2392 for (i
= 0; i
< nboards
; i
++) {
2394 board
->port_base
= portno
;
2395 /* Possibly the configuration was rejected. */
2396 sx_dprintk (SX_DEBUG_PROBE
, "Board has %d channels\n", board
->nports
);
2397 if (board
->nports
<= 0) continue;
2398 /* XXX byteorder ?? */
2399 for (addr
= 0x80;addr
!= 0;addr
= read_sx_word (board
, addr
) & 0x7fff) {
2400 chans
= sx_read_module_byte (board
, addr
, mc_type
);
2401 sx_dprintk (SX_DEBUG_PROBE
, "Module at %x: %d channels\n", addr
, chans
);
2402 sx_dprintk (SX_DEBUG_PROBE
, "Port at");
2403 for (j
=0;j
<chans
;j
++) {
2404 /* The "sx-way" is the way it SHOULD be done. That way in the
2405 future, the firmware may for example pack the structures a bit
2406 more efficient. Neil tells me it isn't going to happen anytime
2408 if (IS_SX_BOARD(board
))
2409 port
->ch_base
= sx_read_module_word (board
, addr
+j
*2, mc_chan_pointer
);
2411 port
->ch_base
= addr
+ 0x100 + 0x300*j
;
2413 sx_dprintk (SX_DEBUG_PROBE
, " %x", port
->ch_base
);
2414 port
->line
= portno
++;
2417 sx_dprintk (SX_DEBUG_PROBE
, "\n");
2419 /* This has to be done earlier. */
2420 /* board->flags |= SX_BOARD_INITIALIZED; */
2428 static void sx_release_drivers(void)
2431 tty_unregister_driver(&sx_driver
);
2432 tty_unregister_driver(&sx_callout_driver
);
2437 #define PDEV unsigned char pci_bus, unsigned pci_fun
2438 #define pdev pci_bus, pci_fun
2440 #define PDEV struct pci_dev *pdev
2445 /********************************************************
2446 * Setting bit 17 in the CNTRL register of the PLX 9050 *
2447 * chip forces a retry on writes while a read is pending.*
2448 * This is to prevent the card locking up on Intel Xeon *
2449 * multiprocessor systems with the NX chipset. -- NV *
2450 ********************************************************/
2452 /* Newer cards are produced with this bit set from the configuration
2453 EEprom. As the bit is read/write for the CPU, we can fix it here,
2454 if we detect that it isn't set correctly. -- REW */
2456 void fix_sx_pci (PDEV
, struct sx_board
*board
)
2458 unsigned int hwbase
;
2459 unsigned long rebase
;
2462 #define CNTRL_REG_OFFSET 0x50
2463 #define CNTRL_REG_GOODVALUE 0x00260000
2465 pci_read_config_dword(pdev
, PCI_BASE_ADDRESS_0
, &hwbase
);
2466 hwbase
&= PCI_BASE_ADDRESS_MEM_MASK
;
2467 rebase
= (ulong
) ioremap(hwbase
, 0x80);
2468 t
= readl (rebase
+ CNTRL_REG_OFFSET
);
2469 if (t
!= CNTRL_REG_GOODVALUE
) {
2470 printk (KERN_DEBUG
"sx: performing cntrl reg fix: %08x -> %08x\n", t
, CNTRL_REG_GOODVALUE
);
2471 writel (CNTRL_REG_GOODVALUE
, rebase
+ CNTRL_REG_OFFSET
);
2473 my_iounmap (hwbase
, rebase
);
2479 #define sx_init init_module
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
,
2515 for (i
=0;i
< SX_NBOARDS
;i
++) {
2516 if (pcibios_find_device (PCI_VENDOR_ID_SPECIALIX
,
2517 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
, i
,
2518 &pci_bus
, &pci_fun
)) break;
2520 /* Specialix has a whole bunch of cards with
2521 0x2000 as the device ID. They say its because
2522 the standard requires it. Stupid standard. */
2523 /* It seems that reading a word doesn't work reliably on 2.0.
2524 Also, reading a non-aligned dword doesn't work. So we read the
2525 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
2527 /* I don't know why the define doesn't work, constant 0x2c does --REW */
2528 pci_read_config_dword (pdev
, 0x2c, &tint
);
2529 tshort
= (tint
>> 16) & 0xffff;
2530 sx_dprintk (SX_DEBUG_PROBE
, "Got a specialix card: %x.\n", tint
);
2531 /* sx_dprintk (SX_DEBUG_PROBE, "pdev = %d/%d (%x)\n", pdev, tint); */
2532 if (tshort
!= 0x0200) {
2533 sx_dprintk (SX_DEBUG_PROBE
, "But it's not an SX card (%d)...\n",
2537 board
= &boards
[found
];
2539 pci_read_config_dword(pdev
, PCI_BASE_ADDRESS_2
, &tint
);
2540 board
->hw_base
= tint
& PCI_BASE_ADDRESS_MEM_MASK
;
2541 board
->base
= (ulong
) ioremap(board
->hw_base
, SX_WINDOW_LEN
);
2542 board
->irq
= get_irq (pdev
);
2543 board
->flags
&= ~SX_BOARD_TYPE
;
2544 board
->flags
|= SX_PCI_BOARD
;
2546 sx_dprintk (SX_DEBUG_PROBE
, "Got a specialix card: %x/%x(%d).\n",
2547 tint
, boards
[found
].base
, board
->irq
);
2549 if (probe_sx (board
)) {
2551 fix_sx_pci (pdev
, board
);
2553 my_iounmap (board
->hw_base
, board
->base
);
2558 for (i
=0;i
<NR_SX_ADDRS
;i
++) {
2559 board
= &boards
[found
];
2560 board
->hw_base
= sx_probe_addrs
[i
];
2561 board
->base
= (ulong
) ioremap(board
->hw_base
, SX_WINDOW_LEN
);
2562 board
->flags
&= ~SX_BOARD_TYPE
;
2563 board
->flags
|= SX_ISA_BOARD
;
2564 board
->irq
= sx_irqmask
?-1:0;
2566 if (probe_sx (board
)) {
2569 my_iounmap (board
->hw_base
, board
->base
);
2573 for (i
=0;i
<NR_SI_ADDRS
;i
++) {
2574 board
= &boards
[found
];
2575 board
->hw_base
= si_probe_addrs
[i
];
2576 board
->base
= (ulong
) ioremap(board
->hw_base
, SI2_ISA_WINDOW_LEN
);
2577 board
->flags
&= ~SX_BOARD_TYPE
;
2578 board
->flags
|= SI_ISA_BOARD
;
2579 board
->irq
= sx_irqmask
?-1:0;
2581 if (probe_si (board
)) {
2584 my_iounmap (board
->hw_base
, board
->base
);
2589 printk (KERN_INFO
"sx: total of %d boards detected.\n", found
);
2591 if (misc_register(&sx_fw_device
) < 0) {
2592 printk(KERN_ERR
"SX: Unable to register firmware loader driver.\n");
2598 return found
?0:-EIO
;
2603 void cleanup_module(void)
2606 struct sx_board
*board
;
2609 for (i
= 0; i
< SX_NBOARDS
; i
++) {
2611 if (board
->flags
& SX_BOARD_INITIALIZED
) {
2612 sx_dprintk (SX_DEBUG_CLEANUP
, "Cleaning up board at %x\n", board
->base
);
2613 /* The board should stop messing with us.
2614 (actually I mean the interrupt) */
2616 if ((board
->irq
) && (board
->flags
& SX_IRQ_ALLOCATED
))
2617 free_irq (board
->irq
, board
);
2619 /* It is safe/allowed to del_timer a non-active timer */
2620 del_timer (& board
->timer
);
2621 my_iounmap (board
->hw_base
, board
->base
);
2624 if (misc_deregister(&sx_fw_device
) < 0) {
2625 printk (KERN_INFO
"sx: couldn't deregister firmware loader device\n");
2627 sx_dprintk (SX_DEBUG_CLEANUP
, "Cleaning up drivers (%d)\n", sx_initialized
);
2629 sx_release_drivers ();
2633 kfree (sx_termios_locked
);
2639 void my_hd (unsigned char *addr
, int len
)
2643 for (i
=0;i
<len
;i
+=16) {
2644 printk ("%08x ", (int) addr
+i
);
2645 for (j
=0;j
<16;j
++) {
2646 printk ("%02x %s", addr
[j
+i
], (j
==7)?" ":"");
2648 for (j
=0;j
<16;j
++) {
2650 printk ("%c", (ch
< 0x20)?'.':((ch
> 0x7f)?'.':ch
));
2661 #include "generic_serial.c"
2666 * Anybody who knows why this doesn't work for me, please tell me -- REW.
2667 * Snatched from scsi.c (fixed one spelling error):
2668 * Overrides for Emacs so that we follow Linus' tabbing style.
2669 * Emacs will notice this stuff at the end of the file and automatically
2670 * adjust the settings for this buffer only. This must remain at the end
2672 * ---------------------------------------------------------------------------
2675 * c-brace-imaginary-offset: 0
2676 * c-brace-offset: -4
2677 * c-argdecl-indent: 4
2678 * c-label-offset: -4
2679 * c-continued-statement-offset: 4
2680 * c-continued-brace-offset: 0
2681 * indent-tabs-mode: nil