Import 2.3.25pre1
[davej-history.git] / drivers / char / sx.c
blob6ff32878393f58bdb2cab26a82b00a1395682bd9
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
11 * yet :-)
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,
32 * USA.
34 * Revision history:
35 * $Log: sx.c,v $
36 * Revision 1.26 1999/08/05 15:22:14 wolff
37 * - Port to 2.3.x
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
46 * fixed now.
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
64 * reporting this.
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
88 * into clocal mode..
90 * Revision 1.14 1999/05/25 11:18:59 wolff
91 * Added PCI-fix.
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
142 * rcs cleanup
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
151 * cleanup. Not good.
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
160 * Port to 2.0
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.
185 * */
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>
195 #include <asm/io.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.... */
215 #define BYTE u8
216 #define WORD u16
218 /* .... but the 3.0.4 version uses _u8 and _u16. */
219 #define _u8 u8
220 #define _u16 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 */
237 #define TWO_ZERO
238 #else
239 #if LINUX_VERSION_CODE < 0x020200 /* less than 2.2.x */
240 #warning "Please use a 2.2.x kernel. "
241 #else
242 #if LINUX_VERSION_CODE < 0x020300 /* less than 2.3.x */
243 #define TWO_TWO
244 #else
245 #define TWO_THREE
246 #endif
247 #endif
248 #endif
250 #ifdef TWO_ZERO
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);
265 return 0;
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)
274 unsigned char t;
275 pcibios_read_config_byte (bus, fn, PCI_INTERRUPT_LINE, &t);
276 return 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. */
314 #define INT void
315 #define NO_ERROR /* Nothing */
317 #else
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
327 #define INT int
328 #define NO_ERROR 0
330 #define my_iounmap(x,b) (iounmap((char *)(b)))
332 #endif
334 #ifndef TWO_THREE
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 }
341 #endif
343 #undef RS_EVENT_WRITE_WAKEUP
344 #define RS_EVENT_WRITE_WAKEUP 0
347 #include "generic_serial.h"
348 #include "sx.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
366 #endif
368 #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
369 #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
370 #endif
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
395 #if 0
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
403 #endif
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;
436 int sx_refcount;
437 int sx_initialized = 0;
438 int sx_nports = 0;
439 int sx_debug = 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....
450 int sx_poll = 1;
451 int sx_slowpoll = 0;
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
461 or less.... */
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. */
473 int sx_irqmask = -1;
475 #ifndef TWO_ZERO
476 #ifdef MODULE
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");
482 #endif
483 #endif
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,
490 sx_get_CD,
491 sx_shutdown_port,
492 sx_set_real_termios,
493 sx_chars_in_buffer,
494 sx_close,
495 sx_hungup,
496 NULL
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
506 them to recompile...
508 #define DEBUG
511 #ifdef DEBUG
512 #define sx_dprintk(f, str...) if (sx_debug & f) printk (str)
513 #else
514 #define sx_dprintk(f, str...) /* nothing */
515 #endif
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 = {
534 NULL, /* lseek */
535 NULL, /* read */
536 NULL, /* write */
537 NULL, /* readdir */
538 NULL, /* select */
539 sx_fw_ioctl,
540 NULL, /* mmap */
541 sx_fw_open,
542 #ifndef TWO_ZERO
543 NULL, /* flush */
544 #endif
545 sx_fw_release,
546 NULL, /* fsync */
547 NULL, /* fasync */
548 NULL, /* check_media_change */
549 NULL, /* revalidate */
552 struct miscdevice sx_fw_device = {
553 SXCTL_MISC_MINOR, "sxctl", &sx_fw_fops
560 #ifdef SX_PARANOIA_CHECK
562 /* This doesn't work. Who's paranoid around here? Not me! */
564 static inline int sx_paranoia_check(struct sx_port const * port,
565 kdev_t device, const char *routine)
568 static const char *badmagic =
569 KERN_ERR "sx: Warning: bad sx port magic number for device %s in %s\n";
570 static const char *badinfo =
571 KERN_ERR "sx: Warning: null sx port for device %s in %s\n";
573 if (!port) {
574 printk(badinfo, kdevname(device), routine);
575 return 1;
577 if (port->magic != SX_MAGIC) {
578 printk(badmagic, kdevname(device), routine);
579 return 1;
582 return 0;
584 #else
585 #define sx_paranoia_check(a,b,c) 0
586 #endif
588 /* The timeouts. First try 30 times as fast as possible. Then give
589 the card some time to breathe between accesses. (Otherwise the
590 processor on the card might not be able to access its OWN bus... */
592 #define TIMEOUT_1 30
593 #define TIMEOUT_2 1000000
596 /* This needs redoing for Alpha -- REW -- Done. */
598 inline void write_sx_byte (struct sx_board *board, int offset, u8 byte)
600 writeb (byte, board->base+offset);
603 inline u8 read_sx_byte (struct sx_board *board, int offset)
605 return readb (board->base+offset);
609 inline void write_sx_word (struct sx_board *board, int offset, u16 word)
611 writew (word, board->base+offset);
614 inline u16 read_sx_word (struct sx_board *board, int offset)
616 return readw (board->base + offset);
620 int sx_busy_wait_eq (struct sx_board *board,
621 int offset,
622 int mask,
623 int correctval)
625 int i;
627 func_enter ();
629 for (i=0; i < TIMEOUT_1 > 0;i++)
630 if ((read_sx_byte (board, offset) & mask) == correctval) {
631 func_exit ();
632 return 1;
635 for (i=0; i < TIMEOUT_2 > 0;i++) {
636 if ((read_sx_byte (board, offset) & mask) == correctval) {
637 func_exit ();
638 return 1;
640 udelay (1);
643 func_exit ();
644 return 0;
648 int sx_busy_wait_neq (struct sx_board *board,
649 int offset,
650 int mask,
651 int badval)
653 int i;
655 func_enter ();
657 for (i=0; i < TIMEOUT_1 > 0;i++)
658 if ((read_sx_byte (board, offset) & mask) != badval) {
659 func_exit ();
660 return 1;
663 for (i=0; i < TIMEOUT_2 > 0;i++) {
664 if ((read_sx_byte (board, offset) & mask) != badval) {
665 func_exit ();
666 return 1;
668 udelay (1);
671 func_exit ();
672 return 0;
677 /* 5.6.4 of 6210028 r2.3 */
678 int sx_reset (struct sx_board *board)
680 func_enter ();
682 if (IS_SX_BOARD (board)) {
684 write_sx_byte (board, SX_CONFIG, 0);
685 write_sx_byte (board, SX_RESET, 1); /* Value doesn't matter */
687 if (!sx_busy_wait_eq (board, SX_RESET_STATUS, 1, 0)) {
688 printk (KERN_INFO "sx: Card doesn't respond to reset....\n");
689 return 0;
691 } else {
692 /* Gory details of the SI/ISA board */
693 write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_SET);
694 write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_CLEAR);
695 write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_CLEAR);
696 write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_CLEAR);
697 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR);
698 write_sx_byte (board, SI2_ISA_IRQSET, SI2_ISA_IRQSET_CLEAR);
701 func_exit ();
702 return 1;
706 /* This doesn't work on machines where "NULL" isn't 0 */
707 /* If you have one of those, someone will need to write
708 the equivalent of this, which will amount to about 3 lines. I don't
709 want to complicate this right now. -- REW
710 (See, I do write comments every now and then :-) */
711 #define OFFSETOF(strct, elem) ((long)&(((struct strct *)NULL)->elem))
714 #define CHAN_OFFSET(port,elem) (port->ch_base + OFFSETOF (_SXCHANNEL, elem))
715 #define MODU_OFFSET(board,addr,elem) (addr + OFFSETOF (_SXMODULE, elem))
716 #define BRD_OFFSET(board,elem) (OFFSETOF (_SXCARD, elem))
719 #define sx_write_channel_byte(port, elem, val) \
720 write_sx_byte (port->board, CHAN_OFFSET (port, elem), val)
722 #define sx_read_channel_byte(port, elem) \
723 read_sx_byte (port->board, CHAN_OFFSET (port, elem))
725 #define sx_write_channel_word(port, elem, val) \
726 write_sx_word (port->board, CHAN_OFFSET (port, elem), val)
728 #define sx_read_channel_word(port, elem) \
729 read_sx_word (port->board, CHAN_OFFSET (port, elem))
732 #define sx_write_module_byte(board, addr, elem, val) \
733 write_sx_byte (board, MODU_OFFSET (board, addr, elem), val)
735 #define sx_read_module_byte(board, addr, elem) \
736 read_sx_byte (board, MODU_OFFSET (board, addr, elem))
738 #define sx_write_module_word(board, addr, elem, val) \
739 write_sx_word (board, MODU_OFFSET (board, addr, elem), val)
741 #define sx_read_module_word(board, addr, elem) \
742 read_sx_word (board, MODU_OFFSET (board, addr, elem))
745 #define sx_write_board_byte(board, elem, val) \
746 write_sx_byte (board, BRD_OFFSET (board, elem), val)
748 #define sx_read_board_byte(board, elem) \
749 read_sx_byte (board, BRD_OFFSET (board, elem))
751 #define sx_write_board_word(board, elem, val) \
752 write_sx_word (board, BRD_OFFSET (board, elem), val)
754 #define sx_read_board_word(board, elem) \
755 read_sx_word (board, BRD_OFFSET (board, elem))
758 int sx_start_board (struct sx_board *board)
760 if (IS_SX_BOARD (board)) {
761 write_sx_byte (board, SX_CONFIG, SX_CONF_BUSEN);
762 } else {
763 /* Don't bug me about the clear_set.
764 I haven't the foggiest idea what it's about -- REW*/
765 write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_CLEAR);
766 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
768 return 1;
771 #define SX_IRQ_REG_VAL(board) \
772 ((board->flags & SX_ISA_BOARD)?(board->irq << 4):0)
774 /* Note. The SX register is write-only. Therefore, we have to enable the
775 bus too. This is a no-op, if you don't mess with this driver... */
776 int sx_start_interrupts (struct sx_board *board)
779 /* Don't call this with board->irq == 0 */
781 if (IS_SX_BOARD(board)) {
782 write_sx_byte (board, SX_CONFIG, SX_IRQ_REG_VAL (board) |
783 SX_CONF_BUSEN |
784 SX_CONF_HOSTIRQ);
785 } else {
786 switch (board->irq) {
787 case 11:write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_SET);break;
788 case 12:write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_SET);break;
789 case 15:write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_SET);break;
790 default:printk (KERN_INFO "sx: SI/XIO card doesn't support interrupt %d.\n",
791 board->irq);
792 return 0;
794 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
797 return 1;
801 int sx_send_command (struct sx_port *port,
802 int command,
803 int mask,
804 int newstat)
806 func_enter2 ();
807 write_sx_byte (port->board, CHAN_OFFSET (port, hi_hstat), command);
808 func_exit ();
809 return sx_busy_wait_eq (port->board, CHAN_OFFSET (port, hi_hstat), mask, newstat);
813 char *mod_type_s (int module_type)
815 switch (module_type) {
816 case TA4: return "TA4";
817 case TA8: return "TA8";
818 case TA4_ASIC: return "TA4_ASIC";
819 case TA8_ASIC: return "TA8_ASIC";
820 case MTA_CD1400:return "MTA_CD1400";
821 case SXDC: return "SXDC";
822 default:return "Unknown/invalid";
827 char *pan_type_s (int pan_type)
829 switch (pan_type) {
830 case MOD_RS232DB25: return "MOD_RS232DB25";
831 case MOD_RS232RJ45: return "MOD_RS232RJ45";
832 case MOD_RS422DB25: return "MOD_RS422DB25";
833 case MOD_PARALLEL: return "MOD_PARALLEL";
834 case MOD_2_RS232DB25: return "MOD_2_RS232DB25";
835 case MOD_2_RS232RJ45: return "MOD_2_RS232RJ45";
836 case MOD_2_RS422DB25: return "MOD_2_RS422DB25";
837 case MOD_RS232DB25MALE: return "MOD_RS232DB25MALE";
838 case MOD_2_PARALLEL: return "MOD_2_PARALLEL";
839 case MOD_BLANK: return "empty";
840 default:return "invalid";
845 int mod_compat_type (int module_type)
847 return module_type >> 4;
851 static void sx_setsignals (struct sx_port *port, int dtr, int rts)
853 int t;
854 func_enter2 ();
856 t = sx_read_channel_byte (port, hi_op);
857 if (dtr >= 0) t = dtr? (t | OP_DTR): (t & ~OP_DTR);
858 if (rts >= 0) t = rts? (t | OP_RTS): (t & ~OP_RTS);
859 sx_write_channel_byte (port, hi_op, t);
860 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "setsignals: %d/%d\n", dtr, rts);
861 func_exit ();
866 static int sx_getsignals (struct sx_port *port)
868 int i_stat,o_stat;
870 o_stat = sx_read_channel_byte (port, hi_op);
871 i_stat = sx_read_channel_byte (port, hi_ip);
873 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) %02x/%02x\n",
874 (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0,
875 port->c_dcd, sx_get_CD (port),
876 sx_read_channel_byte (port, hi_ip),
877 sx_read_channel_byte (port, hi_state));
879 return (((o_stat & OP_DTR)?TIOCM_DTR:0) |
880 ((o_stat & OP_RTS)?TIOCM_RTS:0) |
881 ((i_stat & IP_CTS)?TIOCM_CTS:0) |
882 ((i_stat & IP_DCD)?TIOCM_CAR:0) |
883 ((i_stat & IP_DSR)?TIOCM_DSR:0) |
884 ((i_stat & IP_RI)?TIOCM_RNG:0)
889 static void sx_set_baud (struct sx_port *port)
891 int t;
893 if (port->board->ta_type == MOD_SXDC) {
894 switch (port->gs.baud) {
895 /* Save some typing work... */
896 #define e(x) case x:t= BAUD_ ## x ; break
897 e(50);e(75);e(110);e(150);e(200);e(300);e(600);
898 e(1200);e(1800);e(2000);e(2400);e(4800);e(7200);
899 e(9600);e(14400);e(19200);e(28800);e(38400);
900 e(56000);e(57600);e(64000);e(76800);e(115200);
901 e(128000);e(150000);e(230400);e(256000);e(460800);
902 e(921600);
903 case 134 :t = BAUD_134_5; break;
904 case 0 :t = -1;
905 break;
906 default:
907 /* Can I return "invalid"? */
908 t = BAUD_9600;
909 printk (KERN_INFO "sx: unsupported baud rate: %d.\n", port->gs.baud);
910 break;
912 #undef e
913 if (t > 0) {
914 /* The baud rate is not set to 0, so we're enabeling DTR... -- REW */
915 sx_setsignals (port, 1, -1);
916 /* XXX This is not TA & MTA compatible */
917 sx_write_channel_byte (port, hi_csr, 0xff);
919 sx_write_channel_byte (port, hi_txbaud, t);
920 sx_write_channel_byte (port, hi_rxbaud, t);
921 } else {
922 sx_setsignals (port, 0, -1);
924 } else {
925 switch (port->gs.baud) {
926 #define e(x) case x:t= CSR_ ## x ; break
927 e(75);e(150);e(300);e(600);e(1200);e(2400);e(4800);
928 e(1800);e(9600);
929 e(19200);e(57600);e(38400);
930 /* TA supports 110, but not 115200, MTA supports 115200, but not 110 */
931 case 110:
932 if (port->board->ta_type == MOD_TA) {
933 t = CSR_110;
934 break;
935 } else {
936 t = CSR_9600;
937 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
938 break;
940 case 115200:
941 if (port->board->ta_type == MOD_TA) {
942 t = CSR_9600;
943 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
944 break;
945 } else {
946 t = CSR_110;
947 break;
949 case 0 :t = -1;
950 break;
951 default:
952 t = CSR_9600;
953 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
954 break;
956 #undef e
957 if (t >= 0) {
958 sx_setsignals (port, 1, -1);
959 sx_write_channel_byte (port, hi_csr, t * 0x11);
960 } else {
961 sx_setsignals (port, 0, -1);
967 /* Simon Allen's version of this routine was 225 lines long. 85 is a lot
968 better. -- REW */
970 static void sx_set_real_termios (void *ptr)
972 struct sx_port *port = ptr;
974 func_enter2();
976 /* What is this doing here? -- REW
977 Ha! figured it out. It is to allow you to get DTR active again
978 if you've dropped it with stty 0. Moved to set_baud, where it
979 belongs (next to the drop dtr if baud == 0) -- REW */
980 /* sx_setsignals (port, 1, -1); */
982 sx_set_baud (port);
984 #define CFLAG port->gs.tty->termios->c_cflag
985 sx_write_channel_byte (port, hi_mr1,
986 (C_PARENB (port->gs.tty)? MR1_WITH:MR1_NONE) |
987 (C_PARODD (port->gs.tty)? MR1_ODD:MR1_EVEN) |
988 (C_CRTSCTS(port->gs.tty)? MR1_RTS_RXFLOW:0) |
989 (((CFLAG & CSIZE)==CS8) ? MR1_8_BITS:0) |
990 (((CFLAG & CSIZE)==CS7) ? MR1_7_BITS:0) |
991 (((CFLAG & CSIZE)==CS6) ? MR1_6_BITS:0) |
992 (((CFLAG & CSIZE)==CS5) ? MR1_5_BITS:0) );
994 sx_write_channel_byte (port, hi_mr2,
995 (C_CRTSCTS(port->gs.tty)?MR2_CTS_TXFLOW:0) |
996 (C_CSTOPB (port->gs.tty)?MR2_2_STOP:MR2_1_STOP));
998 switch (CFLAG & CSIZE) {
999 case CS8:sx_write_channel_byte (port, hi_mask, 0xff);break;
1000 case CS7:sx_write_channel_byte (port, hi_mask, 0x7f);break;
1001 case CS6:sx_write_channel_byte (port, hi_mask, 0x3f);break;
1002 case CS5:sx_write_channel_byte (port, hi_mask, 0x1f);break;
1003 default:
1004 printk (KERN_INFO "sx: Invalid wordsize: %d\n", CFLAG & CSIZE);
1005 break;
1008 sx_write_channel_byte (port, hi_prtcl,
1009 (I_IXON (port->gs.tty)?SP_TXEN:0) |
1010 (I_IXOFF (port->gs.tty)?SP_RXEN:0) |
1011 (I_IXANY (port->gs.tty)?SP_TANY:0) |
1012 SP_DCEN);
1014 sx_write_channel_byte (port, hi_break,
1015 I_OTHER(port->gs.tty) ? 0:
1016 (I_IGNBRK(port->gs.tty)?BR_IGN:0 |
1017 I_BRKINT(port->gs.tty)?BR_INT:0));
1019 sx_write_channel_byte (port, hi_txon, START_CHAR (port->gs.tty));
1020 sx_write_channel_byte (port, hi_rxon, START_CHAR (port->gs.tty));
1021 sx_write_channel_byte (port, hi_txoff, STOP_CHAR (port->gs.tty));
1022 sx_write_channel_byte (port, hi_rxoff, STOP_CHAR (port->gs.tty));
1024 if (sx_read_channel_byte (port, hi_hstat) == HS_IDLE_OPEN) {
1025 if (sx_send_command (port, HS_CONFIG, -1, HS_IDLE_OPEN) != 1) {
1026 printk (KERN_WARNING "sx: Sent reconfigure command, but card didn't react.\n");
1028 } else {
1029 sx_dprintk (SX_DEBUG_TERMIOS,
1030 "sx: Not sending reconfigure: port isn't open (%02x).\n",
1031 sx_read_channel_byte (port, hi_hstat));
1035 /* Tell line discipline whether we will do input cooking */
1036 if(I_OTHER(port->gs.tty)) {
1037 clear_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
1038 } else {
1039 set_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
1041 sx_dprintk (SX_DEBUG_TERMIOS, "iflags: %x(%d) ",
1042 port->gs.tty->termios->c_iflag,
1043 I_OTHER(port->gs.tty));
1046 /* Tell line discipline whether we will do output cooking.
1047 * If OPOST is set and no other output flags are set then we can do output
1048 * processing. Even if only *one* other flag in the O_OTHER group is set
1049 * we do cooking in software.
1051 if(O_OPOST(port->gs.tty) && !O_OTHER(port->gs.tty)) {
1052 set_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
1053 } else {
1054 clear_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
1056 sx_dprintk (SX_DEBUG_TERMIOS, "oflags: %x(%d)\n",
1057 port->gs.tty->termios->c_oflag,
1058 O_OTHER(port->gs.tty));
1059 /* port->c_dcd = sx_get_CD (port); */
1060 func_exit ();
1065 /* ********************************************************************** *
1066 * the interrupt related routines *
1067 * ********************************************************************** */
1069 /* Note:
1070 Other drivers use the macro "MIN" to calculate how much to copy.
1071 This has the disadvantage that it will evaluate parts twice. That's
1072 expensive when it's IO (and the compiler cannot optimize those away!).
1073 Moreover, I'm not sure that you're race-free.
1075 I assign a value, and then only allow the value to decrease. This
1076 is always safe. This makes the code a few lines longer, and you
1077 know I'm dead against that, but I think it is required in this
1078 case. */
1081 void sx_transmit_chars (struct sx_port *port)
1083 int c;
1084 int tx_ip;
1085 int txroom;
1087 func_enter2 ();
1088 sx_dprintk (SX_DEBUG_TRANSMIT, "Port %p: transmit %d chars\n",
1089 port, port->gs.xmit_cnt);
1091 if (test_and_set_bit (SX_PORT_TRANSMIT_LOCK, &port->locks)) {
1092 return;
1095 while (1) {
1096 c = port->gs.xmit_cnt;
1098 sx_dprintk (SX_DEBUG_TRANSMIT, "Copying %d ", c);
1099 tx_ip = sx_read_channel_byte (port, hi_txipos);
1101 /* Took me 5 minutes to deduce this formula.
1102 Luckily it is literally in the manual in section 6.5.4.3.5 */
1103 txroom = (sx_read_channel_byte (port, hi_txopos) - tx_ip - 1) & 0xff;
1105 /* Don't copy more bytes than there is room for in the buffer */
1106 if (c > txroom)
1107 c = txroom;
1108 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, txroom );
1110 /* Don't copy past the end of the hardware transmit buffer */
1111 if (c > 0x100 - tx_ip)
1112 c = 0x100 - tx_ip;
1114 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, 0x100-tx_ip );
1116 /* Don't copy pas the end of the source buffer */
1117 if (c > SERIAL_XMIT_SIZE - port->gs.xmit_tail)
1118 c = SERIAL_XMIT_SIZE - port->gs.xmit_tail;
1120 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) \n",
1121 c, SERIAL_XMIT_SIZE- port->gs.xmit_tail);
1123 /* If for one reason or another, we can't copy more data, we're done! */
1124 if (c == 0) break;
1127 memcpy_toio (port->board->base + CHAN_OFFSET(port,hi_txbuf) + tx_ip,
1128 port->gs.xmit_buf + port->gs.xmit_tail, c);
1130 /* Update the pointer in the card */
1131 sx_write_channel_byte (port, hi_txipos, (tx_ip+c) & 0xff);
1133 /* Update the kernel buffer end */
1134 port->gs.xmit_tail = (port->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE-1);
1136 /* This one last. (this is essential)
1137 It would allow others to start putting more data into the buffer! */
1138 port->gs.xmit_cnt -= c;
1141 if (port->gs.xmit_cnt == 0) {
1142 sx_disable_tx_interrupts (port);
1145 if (port->gs.xmit_cnt <= port->gs.wakeup_chars) {
1146 if ((port->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1147 port->gs.tty->ldisc.write_wakeup)
1148 (port->gs.tty->ldisc.write_wakeup)(port->gs.tty);
1149 sx_dprintk (SX_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n",
1150 port->gs.wakeup_chars);
1151 wake_up_interruptible(&port->gs.tty->write_wait);
1154 clear_bit (SX_PORT_TRANSMIT_LOCK, &port->locks);
1155 func_exit ();
1159 /* Note the symmetry between receiving chars and transmitting them!
1160 Note: The kernel should have implemented both a receive buffer and
1161 a transmit buffer. */
1163 /* Inlined: Called only once. Remove the inline when you add another call */
1164 inline void sx_receive_chars (struct sx_port *port)
1166 int c;
1167 int rx_op;
1168 struct tty_struct *tty;
1169 int copied=0;
1171 /* func_enter2 (); */
1172 tty = port->gs.tty;
1173 while (1) {
1174 rx_op = sx_read_channel_byte (port, hi_rxopos);
1175 c = (sx_read_channel_byte (port, hi_rxipos) - rx_op) & 0xff;
1177 sx_dprintk (SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c);
1179 /* Don't copy more bytes than there is room for in the buffer */
1180 if (tty->flip.count + c > TTY_FLIPBUF_SIZE)
1181 c = TTY_FLIPBUF_SIZE - tty->flip.count;
1183 sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
1185 /* Don't copy past the end of the hardware receive buffer */
1186 if (rx_op + c > 0x100) c = 0x100 - rx_op;
1188 sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
1190 /* If for one reason or another, we can't copy more data, we're done! */
1191 if (c == 0) break;
1193 sx_dprintk (SX_DEBUG_RECEIVE , "Copying over %d chars. First is %d at %lx\n", c,
1194 read_sx_byte (port->board, CHAN_OFFSET(port,hi_rxbuf) + rx_op),
1195 CHAN_OFFSET(port, hi_rxbuf));
1196 memcpy_fromio (tty->flip.char_buf_ptr,
1197 port->board->base + CHAN_OFFSET(port,hi_rxbuf) + rx_op, c);
1198 memset(tty->flip.flag_buf_ptr, TTY_NORMAL, c);
1200 /* Update the kernel buffer end */
1201 tty->flip.count += c;
1202 tty->flip.char_buf_ptr += c;
1203 tty->flip.flag_buf_ptr += c;
1205 /* This one last. ( Not essential.)
1206 It allows the card to start putting more data into the buffer!
1207 Update the pointer in the card */
1208 sx_write_channel_byte (port, hi_rxopos, (rx_op + c) & 0xff);
1210 copied += c;
1212 if (copied) {
1213 struct timeval tv;
1215 do_gettimeofday (&tv);
1216 sx_dprintk (SX_DEBUG_RECEIVE,
1217 "pushing flipq port %d (%3d chars): %d.%06d (%d/%d)\n",
1218 port->line, copied,
1219 (int) (tv.tv_sec % 60), (int)tv.tv_usec, tty->raw, tty->real_raw);
1221 /* Tell the rest of the system the news. Great news. New characters! */
1222 tty_flip_buffer_push (tty);
1223 /* tty_schedule_flip (tty); */
1226 /* func_exit (); */
1229 /* Inlined: it is called only once. Remove the inline if you add another
1230 call */
1231 inline void sx_check_modem_signals (struct sx_port *port)
1233 int hi_state;
1234 int c_dcd;
1236 hi_state = sx_read_channel_byte (port, hi_state);
1237 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n",
1238 port->c_dcd, sx_get_CD (port));
1240 if (hi_state & ST_BREAK) {
1241 hi_state &= ~ST_BREAK;
1242 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a break.\n");
1244 sx_write_channel_byte (port, hi_state, hi_state);
1245 if (port->gs.flags & ASYNC_SAK) {
1246 do_SAK (port->gs.tty);
1249 if (hi_state & ST_DCD) {
1250 hi_state &= ~ST_DCD;
1251 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n");
1252 sx_write_channel_byte (port, hi_state, hi_state);
1253 c_dcd = sx_get_CD (port);
1254 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd);
1255 if (c_dcd != port->c_dcd) {
1256 port->c_dcd = c_dcd;
1257 if (sx_get_CD (port)) {
1258 /* DCD went UP */
1259 if( (~(port->gs.flags & ASYNC_NORMAL_ACTIVE) ||
1260 ~(port->gs.flags & ASYNC_CALLOUT_ACTIVE)) &&
1261 (sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED)) {
1262 /* Are we blocking in open?*/
1263 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD active, unblocking open\n");
1264 wake_up_interruptible(&port->gs.open_wait);
1265 } else {
1266 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD raised. Ignoring.\n");
1268 } else {
1269 /* DCD went down! */
1270 if (!((port->gs.flags & ASYNC_CALLOUT_ACTIVE) &&
1271 (port->gs.flags & ASYNC_CALLOUT_NOHUP))) {
1272 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. hanging up....\n");
1273 tty_hangup (port->gs.tty);
1274 } else {
1275 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. ignoring.\n");
1278 } else {
1279 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Hmmm. card told us DCD changed, but it didn't.\n");
1285 /* This is what an interrupt routine should look like.
1286 * Small, elegant, clear.
1289 static void sx_interrupt (int irq, void *ptr, struct pt_regs *regs)
1291 struct sx_board *board = ptr;
1292 struct sx_port *port;
1293 int i;
1295 /* func_enter (); */
1296 sx_dprintk (SX_DEBUG_FLOW, "sx: enter sx_interrupt (%d/%d)\n", irq, board->irq);
1298 /* AAargh! The order in which to do these things is essential and
1299 not trivial.
1301 - Rate limit goes before "recursive". Otherwise a series of
1302 recursive calls will hang the machine in the interrupt routine.
1304 - hardware twiddling goes before "recursive". Otherwise when we
1305 poll the card, and a recursive interrupt happens, we wont
1306 ack the card, so it might keep on interrupting us. (especially
1307 level sensitive interrupt systems like PCI).
1309 - Rate limit goes before hardware twiddling. Otherwise we won't
1310 catch a card that has gone bonkers.
1312 - The "initialized" test goes after the hardware twiddling. Otherwise
1313 the card will stick us in the interrupt routine again.
1315 - The initialized test goes before recursive.
1320 #ifdef IRQ_RATE_LIMIT
1321 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
1322 actual interrupt routine!. (Well, used to when I wrote that comment) */
1324 static int lastjif;
1325 static int nintr=0;
1327 if (lastjif == jiffies) {
1328 if (++nintr > IRQ_RATE_LIMIT) {
1329 free_irq (board->irq, board);
1330 printk (KERN_ERR "sx: Too many interrupts. Turning off interrupt %d.\n",
1331 board->irq);
1333 } else {
1334 lastjif = jiffies;
1335 nintr = 0;
1338 #endif
1341 if (board->irq == irq) {
1342 /* Tell the card we've noticed the interrupt. */
1344 sx_write_board_word (board, cc_int_pending, 0);
1345 if (IS_SX_BOARD (board)) {
1346 write_sx_byte (board, SX_RESET_IRQ, 1);
1347 } else {
1348 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR);
1349 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
1353 if (!sx_initialized) return;
1354 if (!(board->flags & SX_BOARD_INITIALIZED)) return;
1356 if (test_and_set_bit (SX_BOARD_INTR_LOCK, &board->locks)) {
1357 printk (KERN_ERR "Recursive interrupt! (%d)\n", board->irq);
1358 return;
1361 for (i=0;i<board->nports;i++) {
1362 port = &board->ports[i];
1363 if (port->gs.flags & GS_ACTIVE) {
1364 if (sx_read_channel_byte (port, hi_state)) {
1365 sx_dprintk (SX_DEBUG_INTERRUPTS,
1366 "Port %d: modem signal change?... \n", i);
1367 sx_check_modem_signals (port);
1369 if (port->gs.xmit_cnt) {
1370 sx_transmit_chars (port);
1372 if (!(port->gs.flags & SX_RX_THROTTLE)) {
1373 sx_receive_chars (port);
1378 clear_bit (SX_BOARD_INTR_LOCK, &board->locks);
1380 sx_dprintk (SX_DEBUG_FLOW, "sx: exit sx_interrupt (%d/%d)\n", irq, board->irq);
1381 /* func_exit (); */
1385 static void sx_pollfunc (unsigned long data)
1387 struct sx_board *board = (struct sx_board *) data;
1389 func_enter ();
1391 sx_interrupt (0, board, NULL);
1393 board->timer.expires = jiffies + sx_poll;
1394 add_timer (&board->timer);
1395 func_exit ();
1400 /* ********************************************************************** *
1401 * Here are the routines that actually *
1402 * interface with the generic_serial driver *
1403 * ********************************************************************** */
1405 /* Ehhm. I don't know how to fiddle with interrupts on the SX card. --REW */
1406 /* Hmm. Ok I figured it out. You don't. */
1408 static void sx_disable_tx_interrupts (void * ptr)
1410 struct sx_port *port = ptr;
1411 func_enter2();
1413 port->gs.flags &= ~GS_TX_INTEN;
1415 func_exit();
1419 static void sx_enable_tx_interrupts (void * ptr)
1421 struct sx_port *port = ptr;
1422 int data_in_buffer;
1423 func_enter2();
1425 /* First transmit the characters that we're supposed to */
1426 sx_transmit_chars (port);
1428 /* The sx card will never interrupt us if we don't fill the buffer
1429 past 25%. So we keep considering interrupts off if that's the case. */
1430 data_in_buffer = (sx_read_channel_byte (port, hi_txipos) -
1431 sx_read_channel_byte (port, hi_txopos)) & 0xff;
1433 /* XXX Must be "HIGH_WATER" for SI card according to doc. */
1434 if (data_in_buffer < LOW_WATER)
1435 port->gs.flags &= ~GS_TX_INTEN;
1437 func_exit();
1441 static void sx_disable_rx_interrupts (void * ptr)
1443 /* struct sx_port *port = ptr; */
1444 func_enter();
1446 func_exit();
1449 static void sx_enable_rx_interrupts (void * ptr)
1451 /* struct sx_port *port = ptr; */
1452 func_enter();
1454 func_exit();
1458 /* Jeez. Isn't this simple? */
1459 static int sx_get_CD (void * ptr)
1461 struct sx_port *port = ptr;
1462 func_enter2();
1464 func_exit();
1465 return ((sx_read_channel_byte (port, hi_ip) & IP_DCD) != 0);
1469 /* Jeez. Isn't this simple? */
1470 static int sx_chars_in_buffer (void * ptr)
1472 struct sx_port *port = ptr;
1473 func_enter2();
1475 func_exit();
1476 return ((sx_read_channel_byte (port, hi_txipos) -
1477 sx_read_channel_byte (port, hi_txopos)) & 0xff);
1481 static void sx_shutdown_port (void * ptr)
1483 struct sx_port *port = ptr;
1485 func_enter();
1487 port->gs.flags &= ~ GS_ACTIVE;
1488 if (port->gs.tty && port->gs.tty->termios->c_cflag & HUPCL) {
1489 sx_setsignals (port, 0, 0);
1492 func_exit();
1499 /* ********************************************************************** *
1500 * Here are the routines that actually *
1501 * interface with the rest of the system *
1502 * ********************************************************************** */
1505 static int sx_fw_open(struct inode *inode, struct file *filp)
1507 func_enter ();
1508 MOD_INC_USE_COUNT;
1509 func_exit ();
1510 return 0;
1514 static INT sx_fw_release(struct inode *inode, struct file *filp)
1516 func_enter ();
1517 MOD_DEC_USE_COUNT;
1518 func_exit ();
1519 return NO_ERROR;
1523 static int sx_open (struct tty_struct * tty, struct file * filp)
1525 struct sx_port *port;
1526 int retval, line;
1528 func_enter();
1530 if (!sx_initialized) {
1531 return -EIO;
1534 line = MINOR(tty->device);
1535 sx_dprintk (SX_DEBUG_OPEN, "%d: opening line %d. tty=%p ctty=%p, np=%d)\n",
1536 current->pid, line, tty, current->tty, sx_nports);
1538 if ((line < 0) || (line >= SX_NPORTS) || (line >= sx_nports))
1539 return -ENODEV;
1541 port = & sx_ports[line];
1542 port->c_dcd = 0; /* Make sure that the first interrupt doesn't detect a
1543 1 -> 0 transition. */
1546 sx_dprintk (SX_DEBUG_OPEN, "port = %p c_dcd = %d\n", port, port->c_dcd);
1548 tty->driver_data = port;
1549 port->gs.tty = tty;
1550 port->gs.count++;
1552 sx_dprintk (SX_DEBUG_OPEN, "starting port\n");
1555 * Start up serial port
1557 retval = gs_init_port(&port->gs);
1558 sx_dprintk (SX_DEBUG_OPEN, "done gs_init\n");
1559 if (retval) {
1560 port->gs.count--;
1561 return retval;
1564 port->gs.flags |= GS_ACTIVE;
1565 sx_setsignals (port, 1,1);
1567 sx_dprintk (SX_DEBUG_OPEN, "before inc_use_count (count=%d.\n",
1568 port->gs.count);
1569 if (port->gs.count == 1) {
1570 MOD_INC_USE_COUNT;
1572 sx_dprintk (SX_DEBUG_OPEN, "after inc_use_count\n");
1574 #if 0
1575 if (sx_debug & SX_DEBUG_OPEN)
1576 my_hd ((unsigned char *)port, sizeof (*port));
1577 #else
1578 if (sx_debug & SX_DEBUG_OPEN)
1579 my_hd ((unsigned char *)port->board->base + port->ch_base,
1580 sizeof (*port));
1581 #endif
1583 if (sx_send_command (port, HS_LOPEN, -1, HS_IDLE_OPEN) != 1) {
1584 printk (KERN_ERR "sx: Card didn't respond to LOPEN command.\n");
1585 MOD_DEC_USE_COUNT;
1586 port->gs.count--;
1587 return -EIO;
1590 retval = block_til_ready(port, filp);
1591 sx_dprintk (SX_DEBUG_OPEN, "Block til ready returned %d. Count=%d\n",
1592 retval, port->gs.count);
1594 if (retval) {
1595 MOD_DEC_USE_COUNT;
1596 port->gs.count--;
1597 return retval;
1599 /* tty->low_latency = 1; */
1601 if ((port->gs.count == 1) && (port->gs.flags & ASYNC_SPLIT_TERMIOS)) {
1602 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
1603 *tty->termios = port->gs.normal_termios;
1604 else
1605 *tty->termios = port->gs.callout_termios;
1606 sx_set_real_termios (port);
1609 port->gs.session = current->session;
1610 port->gs.pgrp = current->pgrp;
1611 port->c_dcd = sx_get_CD (port);
1612 sx_dprintk (SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd);
1613 func_exit();
1614 return 0;
1619 /* I haven't the foggiest why the decrement use count has to happen
1620 here. The whole linux serial drivers stuff needs to be redesigned.
1621 My guess is that this is a hack to minimize the impact of a bug
1622 elsewhere. Thinking about it some more. (try it sometime) Try
1623 running minicom on a serial port that is driven by a modularized
1624 driver. Have the modem hangup. Then remove the driver module. Then
1625 exit minicom. I expect an "oops". -- REW */
1626 static void sx_hungup (void *ptr)
1628 func_enter ();
1629 MOD_DEC_USE_COUNT;
1630 func_exit ();
1634 static void sx_close (void *ptr)
1636 struct sx_port *port = ptr;
1637 /* Give the port 5 seconds to close down. */
1638 int to = 5 * HZ;
1640 func_enter ();
1641 sx_send_command (port, HS_CLOSE, 0, 0);
1643 while (to-- && (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED)) {
1644 current->state = TASK_INTERRUPTIBLE;
1645 schedule_timeout (1);
1646 if (signal_pending (current))
1647 break;
1649 current->state = TASK_RUNNING;
1650 if (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED) {
1651 if (sx_send_command (port, HS_FORCE_CLOSED, -1, HS_IDLE_CLOSED) != 1) {
1652 printk (KERN_ERR
1653 "sx: sent the force_close command, but card didn't react\n");
1654 } else
1655 sx_dprintk (SX_DEBUG_CLOSE, "sent the force_close command.\n");
1658 sx_dprintk (SX_DEBUG_CLOSE, "waited %d jiffies for close. count=%d\n",
1659 5 * HZ - to - 1, port->gs.count);
1661 MOD_DEC_USE_COUNT;
1662 func_exit ();
1667 /* This is relatively thorough. But then again it is only 20 lines. */
1668 #define MARCHUP for (i=min;i<max;i++)
1669 #define MARCHDOWN for (i=max-1;i>=min;i--)
1670 #define W0 write_sx_byte (board, i, 0x55)
1671 #define W1 write_sx_byte (board, i, 0xaa)
1672 #define R0 if (read_sx_byte (board, i) != 0x55) return 1
1673 #define R1 if (read_sx_byte (board, i) != 0xaa) return 1
1675 /* This memtest takes a human-noticable time. You normally only do it
1676 once a boot, so I guess that it is worth it. */
1677 int do_memtest (struct sx_board *board, int min, int max)
1679 int i;
1681 /* This is a marchb. Theoretically, marchb catches much more than
1682 simpler tests. In practise, the longer test just catches more
1683 intermittent errors. -- REW
1684 (For the theory behind memory testing see:
1685 Testing Semiconductor Memories by A.J. van de Goor.) */
1686 MARCHUP {W0;}
1687 MARCHUP {R0;W1;R1;W0;R0;W1;}
1688 MARCHUP {R1;W0;W1;}
1689 MARCHDOWN {R1;W0;W1;W0;}
1690 MARCHDOWN {R0;W1;W0;}
1692 return 0;
1696 #undef MARCHUP
1697 #undef MARCHDOWN
1698 #undef W0
1699 #undef W1
1700 #undef R0
1701 #undef R1
1703 #define MARCHUP for (i=min;i<max;i+=2)
1704 #define MARCHDOWN for (i=max-1;i>=min;i-=2)
1705 #define W0 write_sx_word (board, i, 0x55aa)
1706 #define W1 write_sx_word (board, i, 0xaa55)
1707 #define R0 if (read_sx_word (board, i) != 0x55aa) return 1
1708 #define R1 if (read_sx_word (board, i) != 0xaa55) return 1
1710 /* This memtest takes a human-noticable time. You normally only do it
1711 once a boot, so I guess that it is worth it. */
1712 int do_memtest_w (struct sx_board *board, int min, int max)
1714 int i;
1716 MARCHUP {W0;}
1717 MARCHUP {R0;W1;R1;W0;R0;W1;}
1718 MARCHUP {R1;W0;W1;}
1719 MARCHDOWN {R1;W0;W1;W0;}
1720 MARCHDOWN {R0;W1;W0;}
1722 return 0;
1726 static int sx_fw_ioctl (struct inode *inode, struct file *filp,
1727 unsigned int cmd, unsigned long arg)
1729 int rc = 0;
1730 int *descr = (int *)arg, i;
1731 static struct sx_board *board = NULL;
1732 int nbytes, offset, data;
1733 char *tmp;
1735 func_enter();
1737 #if 0
1738 /* Removed superuser check: Sysops can use the permissions on the device
1739 file to restrict access. Recommendation: Root only. (root.root 600) */
1740 if (!suser ()) {
1741 return -EPERM;
1743 #endif
1745 sx_dprintk (SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg);
1747 if (!board) board = &boards[0];
1748 if (board->flags & SX_BOARD_PRESENT) {
1749 sx_dprintk (SX_DEBUG_FIRMWARE, "Board present! (%x)\n",
1750 board->flags);
1751 } else {
1752 sx_dprintk (SX_DEBUG_FIRMWARE, "Board not present! (%x) all:",
1753 board->flags);
1754 for (i=0;i< SX_NBOARDS;i++)
1755 sx_dprintk (SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags);
1756 sx_dprintk (SX_DEBUG_FIRMWARE, "\n");
1757 return -EIO;
1760 switch (cmd) {
1761 case SXIO_SET_BOARD:
1762 sx_dprintk (SX_DEBUG_FIRMWARE, "set board to %ld\n", arg);
1763 if (arg > SX_NBOARDS) return -EIO;
1764 sx_dprintk (SX_DEBUG_FIRMWARE, "not out of range\n");
1765 if (!(boards[arg].flags & SX_BOARD_PRESENT)) return -EIO;
1766 sx_dprintk (SX_DEBUG_FIRMWARE, ".. and present!\n");
1767 board = &boards[arg];
1768 break;
1769 case SXIO_GET_TYPE:
1770 rc = IS_SX_BOARD (board)? SX_TYPE_SX:SX_TYPE_SI;
1771 sx_dprintk (SX_DEBUG_FIRMWARE, "returning type= %d\n", rc);
1772 break;
1773 case SXIO_DO_RAMTEST:
1774 if (sx_initialized) /* Already initialized: better not ramtest the board. */
1775 return -EPERM;
1776 if (IS_SX_BOARD (board)) {
1777 rc = do_memtest (board, 0, 0x7000);
1778 if (!rc) rc = do_memtest (board, 0, 0x7000);
1779 /*if (!rc) rc = do_memtest_w (board, 0, 0x7000);*/
1780 } else {
1781 rc = do_memtest (board, 0, 0x7ff8);
1782 /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */
1784 sx_dprintk (SX_DEBUG_FIRMWARE, "returning memtest result= %d\n", rc);
1785 break;
1786 case SXIO_DOWNLOAD:
1787 if (sx_initialized) /* Already initialized */
1788 return -EEXIST;
1789 if (!sx_reset (board))
1790 return -EIO;
1791 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
1793 tmp = kmalloc (SX_CHUNK_SIZE, GFP_USER);
1794 if (!tmp) return -ENOMEM;
1795 Get_user (nbytes, descr++);
1796 Get_user (offset, descr++);
1797 Get_user (data, descr++);
1798 while (nbytes && data) {
1799 for (i=0;i<nbytes;i += SX_CHUNK_SIZE) {
1800 copy_from_user (tmp, (char *)data+i,
1801 (i+SX_CHUNK_SIZE>nbytes)?nbytes-i:SX_CHUNK_SIZE);
1802 memcpy_toio ((char *) (board->base + offset + i), tmp,
1803 (i+SX_CHUNK_SIZE>nbytes)?nbytes-i:SX_CHUNK_SIZE);
1806 Get_user (nbytes, descr++);
1807 Get_user (offset, descr++);
1808 Get_user (data, descr++);
1810 kfree (tmp);
1811 sx_nports += sx_init_board (board);
1812 rc = sx_nports;
1813 break;
1814 case SXIO_INIT:
1815 if (sx_initialized) /* Already initialized */
1816 return -EEXIST;
1817 /* This is not allowed until all boards are initialized... */
1818 for (i=0;i<SX_NBOARDS;i++) {
1819 if ( (boards[i].flags & SX_BOARD_PRESENT) &&
1820 !(boards[i].flags & SX_BOARD_INITIALIZED))
1821 return -EIO;
1823 for (i=0;i<SX_NBOARDS;i++)
1824 if (!(boards[i].flags & SX_BOARD_PRESENT)) break;
1826 sx_dprintk (SX_DEBUG_FIRMWARE, "initing portstructs, %d boards, "
1827 "%d channels, first board: %d ports\n",
1828 i, sx_nports, boards[0].nports);
1829 rc = sx_init_portstructs (i, sx_nports);
1830 sx_init_drivers ();
1831 if (rc >= 0)
1832 sx_initialized++;
1833 break;
1834 case SXIO_SETDEBUG:
1835 sx_debug = arg;
1836 break;
1837 case SXIO_GETDEBUG:
1838 rc = sx_debug;
1839 break;
1840 case SXIO_SETGSDEBUG:
1841 gs_debug = arg;
1842 break;
1843 case SXIO_GETGSDEBUG:
1844 rc = gs_debug;
1845 break;
1846 default:
1847 printk (KERN_WARNING "Unknown ioctl on firmware device (%x).\n", cmd);
1848 break;
1850 func_exit ();
1851 return rc;
1855 static int sx_ioctl (struct tty_struct * tty, struct file * filp,
1856 unsigned int cmd, unsigned long arg)
1858 int rc;
1859 struct sx_port *port = tty->driver_data;
1860 int ival;
1862 /* func_enter2(); */
1864 rc = 0;
1865 switch (cmd) {
1866 case TIOCGSOFTCAR:
1867 rc = Put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1868 (unsigned int *) arg);
1869 break;
1870 case TIOCSSOFTCAR:
1871 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1872 sizeof(int))) == 0) {
1873 Get_user(ival, (unsigned int *) arg);
1874 tty->termios->c_cflag =
1875 (tty->termios->c_cflag & ~CLOCAL) |
1876 (ival ? CLOCAL : 0);
1878 break;
1879 case TIOCGSERIAL:
1880 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1881 sizeof(struct serial_struct))) == 0)
1882 gs_getserial(&port->gs, (struct serial_struct *) arg);
1883 break;
1884 case TIOCSSERIAL:
1885 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1886 sizeof(struct serial_struct))) == 0)
1887 rc = gs_setserial(&port->gs, (struct serial_struct *) arg);
1888 break;
1889 case TIOCMGET:
1890 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1891 sizeof(unsigned int))) == 0) {
1892 ival = sx_getsignals(port);
1893 put_user(ival, (unsigned int *) arg);
1895 break;
1896 case TIOCMBIS:
1897 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1898 sizeof(unsigned int))) == 0) {
1899 Get_user(ival, (unsigned int *) arg);
1900 sx_setsignals(port, ((ival & TIOCM_DTR) ? 1 : -1),
1901 ((ival & TIOCM_RTS) ? 1 : -1));
1903 break;
1904 case TIOCMBIC:
1905 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1906 sizeof(unsigned int))) == 0) {
1907 Get_user(ival, (unsigned int *) arg);
1908 sx_setsignals(port, ((ival & TIOCM_DTR) ? 0 : -1),
1909 ((ival & TIOCM_RTS) ? 0 : -1));
1911 break;
1912 case TIOCMSET:
1913 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1914 sizeof(unsigned int))) == 0) {
1915 Get_user(ival, (unsigned int *) arg);
1916 sx_setsignals(port, ((ival & TIOCM_DTR) ? 1 : 0),
1917 ((ival & TIOCM_RTS) ? 1 : 0));
1919 break;
1921 default:
1922 rc = -ENOIOCTLCMD;
1923 break;
1926 /* func_exit(); */
1927 return rc;
1931 /* The throttle/unthrottle scheme for the Specialix card is different
1932 * from other drivers and deserves some explanation.
1933 * The Specialix hardware takes care of XON/XOFF
1934 * and CTS/RTS flow control itself. This means that all we have to
1935 * do when signalled by the upper tty layer to throttle/unthrottle is
1936 * to make a note of it here. When we come to read characters from the
1937 * rx buffers on the card (sx_receive_chars()) we look to see if the
1938 * upper layer can accept more (as noted here in sx_rx_throt[]).
1939 * If it can't we simply don't remove chars from the cards buffer.
1940 * When the tty layer can accept chars, we again note that here and when
1941 * sx_receive_chars() is called it will remove them from the cards buffer.
1942 * The card will notice that a ports buffer has drained below some low
1943 * water mark and will unflow control the line itself, using whatever
1944 * flow control scheme is in use for that port. -- Simon Allen
1947 static void sx_throttle (struct tty_struct * tty)
1949 struct sx_port *port = (struct sx_port *)tty->driver_data;
1951 func_enter2();
1952 /* If the port is using any type of input flow
1953 * control then throttle the port.
1955 if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) {
1956 port->gs.flags |= SX_RX_THROTTLE;
1958 func_exit();
1962 static void sx_unthrottle (struct tty_struct * tty)
1964 struct sx_port *port = (struct sx_port *)tty->driver_data;
1966 func_enter2();
1967 /* Always unthrottle even if flow control is not enabled on
1968 * this port in case we disabled flow control while the port
1969 * was throttled
1971 port->gs.flags &= ~SX_RX_THROTTLE;
1972 func_exit();
1973 return;
1977 /* ********************************************************************** *
1978 * Here are the initialization routines. *
1979 * ********************************************************************** */
1984 static int sx_init_board (struct sx_board *board)
1986 int addr;
1987 int chans;
1988 int type;
1990 func_enter();
1992 /* This is preceded by downloading the download code. */
1994 board->flags |= SX_BOARD_INITIALIZED;
1996 /* This resets the processor again, to make sure it didn't do any
1997 foolish things while we were downloading the image */
1998 if (!sx_reset (board))
1999 return 0;
2001 sx_start_board (board);
2003 if (!sx_busy_wait_neq (board, 0, 0xff, 0)) {
2004 printk (KERN_ERR "sx: Ooops. Board won't initialize.\n");
2005 return 0;
2008 /* Ok. So now the processor on the card is running. It gathered
2009 some info for us... */
2010 sx_dprintk (SX_DEBUG_INIT, "The sxcard structure:\n");
2011 if (sx_debug & SX_DEBUG_INIT) my_hd ((char *)(board->base), 0x10);
2012 sx_dprintk (SX_DEBUG_INIT, "the first sx_module structure:\n");
2013 if (sx_debug & SX_DEBUG_INIT) my_hd ((char *)(board->base + 0x80), 0x30);
2015 sx_dprintk (SX_DEBUG_INIT,
2016 "init_status: %x, %dk memory, firmware V%x.%02x,\n",
2017 read_sx_byte (board, 0), read_sx_byte(board, 1),
2018 read_sx_byte (board, 5), read_sx_byte(board, 4));
2020 if (read_sx_byte (board, 0) == 0xff) {
2021 printk (KERN_INFO "sx: No modules found. Sorry.\n");
2022 board->nports = 0;
2023 return 0;
2026 chans = 0;
2028 if (IS_SX_BOARD(board)) {
2029 sx_write_board_word (board, cc_int_count, sx_maxints);
2030 } else {
2031 if (sx_maxints)
2032 sx_write_board_word (board, cc_int_count, SI_PROCESSOR_CLOCK/8/sx_maxints);
2035 /* grab the first module type... */
2036 /* board->ta_type = mod_compat_type (read_sx_byte (board, 0x80 + 0x08)); */
2037 board->ta_type = mod_compat_type (sx_read_module_byte (board, 0x80, mc_chip));
2039 /* XXX byteorder */
2040 for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) {
2041 type = sx_read_module_byte (board, addr, mc_chip);
2042 sx_dprintk (SX_DEBUG_INIT, "Module at %x: %d channels\n",
2043 addr, read_sx_byte (board, addr + 2));
2045 chans += sx_read_module_byte (board, addr, mc_type);
2047 sx_dprintk (SX_DEBUG_INIT, "module is an %s, which has %s/%s panels\n",
2048 mod_type_s (type),
2049 pan_type_s (sx_read_module_byte (board, addr, mc_mods) & 0xf),
2050 pan_type_s (sx_read_module_byte (board, addr, mc_mods) >> 4));
2052 sx_dprintk (SX_DEBUG_INIT, "CD1400 versions: %x/%x, ASIC version: %x\n",
2053 sx_read_module_byte (board, addr, mc_rev1),
2054 sx_read_module_byte (board, addr, mc_rev2),
2055 sx_read_module_byte (board, addr, mc_mtaasic_rev));
2057 /* The following combinations are illegal: It should theoretically
2058 work, but timing problems make the bus HANG. */
2060 if (mod_compat_type (type) != board->ta_type) {
2061 printk (KERN_ERR "sx: This is an invalid configuration.\n"
2062 "Don't mix TA/MTA/SXDC on the same hostadapter.\n");
2063 chans=0;
2064 break;
2066 if (IS_SI_BOARD(board) && (mod_compat_type(type) == 4)) {
2067 printk (KERN_ERR "sx: This is an invalid configuration.\n"
2068 "Don't use SXDCs on an SI/XIO adapter.\n");
2069 chans=0;
2070 break;
2072 #if 0 /* Problem fixed: firmware 3.05 */
2073 if (IS_SX_BOARD(board) && (type == TA8)) {
2074 /* There are some issues with the firmware and the DCD/RTS
2075 lines. It might work if you tie them together or something.
2076 It might also work if you get a newer sx_firmware. Therefore
2077 this is just a warning. */
2078 printk (KERN_WARNING "sx: The SX host doesn't work too well "
2079 "with the TA8 adapters.\nSpecialix is working on it.\n");
2081 #endif
2084 if (chans) {
2085 /* board->flags |= SX_BOARD_PRESENT; */
2086 if(board->irq > 0) {
2087 /* fixed irq, probably PCI */
2088 if(sx_irqmask & (1 << board->irq)) { /* may we use this irq? */
2089 if(request_irq(board->irq, sx_interrupt, SA_SHIRQ | SA_INTERRUPT, "sx", board)) {
2090 printk(KERN_ERR "sx: Cannot allocate irq %d.\n", board->irq);
2091 board->irq = 0;
2093 } else
2094 board->irq = 0;
2095 } else if(board->irq < 0 && sx_irqmask) {
2096 /* auto-allocate irq */
2097 int irqnr;
2098 int irqmask = sx_irqmask & (IS_SX_BOARD(board) ? SX_ISA_IRQ_MASK : SI2_ISA_IRQ_MASK);
2099 for(irqnr = 15; irqnr > 0; irqnr--)
2100 if(irqmask & (1 << irqnr))
2101 if(! request_irq(irqnr, sx_interrupt, SA_SHIRQ | SA_INTERRUPT, "sx", board))
2102 break;
2103 if(! irqnr)
2104 printk(KERN_ERR "sx: Cannot allocate IRQ.\n");
2105 board->irq = irqnr;
2106 } else
2107 board->irq = 0;
2109 if (board->irq) {
2110 /* Found a valid interrupt, start up interrupts! */
2111 sx_dprintk (SX_DEBUG_INIT, "Using irq %d.\n", board->irq);
2112 sx_start_interrupts (board);
2113 board->poll = sx_slowpoll;
2114 board->flags |= SX_IRQ_ALLOCATED;
2115 } else {
2116 /* no irq: setup board for polled operation */
2117 board->poll = sx_poll;
2118 sx_dprintk (SX_DEBUG_INIT, "Using poll-interval %d.\n", board->poll);
2121 /* The timer should be initialized anyway: That way we can safely
2122 del_timer it when the module is unloaded. */
2123 init_timer (&board->timer);
2125 if (board->poll) {
2126 board->timer.data = (unsigned long) board;
2127 board->timer.function = sx_pollfunc;
2128 board->timer.expires = jiffies + board->poll;
2129 add_timer (&board->timer);
2131 } else {
2132 board->irq = 0;
2135 board->nports = chans;
2136 sx_dprintk (SX_DEBUG_INIT, "returning %d ports.", board->nports);
2138 func_exit();
2139 return chans;
2143 void printheader(void)
2145 static int header_printed = 0;
2147 if (!header_printed) {
2148 printk (KERN_INFO "Specialix SX driver "
2149 "(C) 1998/1999 R.E.Wolff@BitWizard.nl \n");
2150 printk (KERN_INFO "sx: version %s\n", RCS_ID);
2151 header_printed = 1;
2156 int probe_sx (struct sx_board *board)
2158 struct vpd_prom vpdp;
2159 char *p;
2160 int i;
2162 func_enter();
2163 sx_dprintk (SX_DEBUG_PROBE, "Going to verify vpd prom at %x.\n",
2164 board->base + SX_VPD_ROM);
2166 if (sx_debug & SX_DEBUG_PROBE)
2167 my_hd ((char *)(board->base + SX_VPD_ROM), 0x40);
2169 p = (char *) &vpdp;
2170 for (i=0;i< sizeof (struct vpd_prom);i++)
2171 *p++ = read_sx_byte (board, SX_VPD_ROM + i*2);
2173 if (sx_debug & SX_DEBUG_PROBE)
2174 my_hd ((char *)&vpdp, 0x20);
2176 sx_dprintk (SX_DEBUG_PROBE, "checking identifier...\n");
2178 if (strncmp (vpdp.identifier, SX_VPD_IDENT_STRING, 16) != 0) {
2179 sx_dprintk (SX_DEBUG_PROBE, "Got non-SX identifier: '%s'\n",
2180 vpdp.identifier);
2181 return 0;
2184 printheader ();
2186 printk (KERN_DEBUG "sx: Found an SX board at %x\n", board->hw_base);
2187 printk (KERN_DEBUG "sx: hw_rev: %d, assembly level: %d, uniq ID:%08x, ",
2188 vpdp.hwrev, vpdp.hwass, vpdp.uniqid);
2189 printk ( "Manufactured: %d/%d\n",
2190 1970 + vpdp.myear, vpdp.mweek);
2193 if ((((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_PCI_UNIQUEID1) &&
2194 (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_ISA_UNIQUEID1)) {
2195 /* This might be a bit harsh. This was the primary reason the
2196 SX/ISA card didn't work at first... */
2197 printk (KERN_ERR "sx: Hmm. Not an SX/PCI or SX/ISA card. Sorry: giving up.\n");
2198 return (0);
2201 if (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) == SX_ISA_UNIQUEID1) {
2202 if (board->base & 0x8000) {
2203 printk (KERN_WARNING "sx: Warning: There may be hardware problems with the card at %x.\n", board->base);
2204 printk (KERN_WARNING "sx: Read sx.txt for more info.\n");
2209 board->nports = -1;
2211 /* This resets the processor, and keeps it off the bus. */
2212 if (!sx_reset (board))
2213 return 0;
2214 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
2216 board->flags |= SX_BOARD_PRESENT;
2218 func_exit();
2219 return 1;
2224 /* Specialix probes for this card at 32k increments from 640k to 16M.
2225 I consider machines with less than 16M unlikely nowadays, so I'm
2226 not probing above 1Mb. Also, 0xa0000, 0xb0000, are taken by the VGA
2227 card. 0xe0000 and 0xf0000 are taken by the BIOS. That only leaves
2228 0xc0000, 0xc8000, 0xd0000 and 0xd8000 . */
2230 int probe_si (struct sx_board *board)
2232 int i;
2234 func_enter();
2235 sx_dprintk (SX_DEBUG_PROBE, "Going to verify SI signature %x.\n",
2236 board->base + SI2_ISA_ID_BASE);
2238 if (sx_debug & SX_DEBUG_PROBE)
2239 my_hd ((char *)(board->base + SI2_ISA_ID_BASE), 0x8);
2241 for (i=0;i<8;i++) {
2242 if ((read_sx_byte (board, SI2_ISA_ID_BASE+7-i) & 7) != i) {
2243 return 0;
2247 printheader ();
2249 printk (KERN_DEBUG "sx: Found an SI board at %x\n", board->hw_base);
2250 /* Compared to the SX boards, it is a complete guess as to what
2251 this card is up to... */
2253 board->nports = -1;
2255 /* This resets the processor, and keeps it off the bus. */
2256 if (!sx_reset (board))
2257 return 0;
2258 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
2260 board->flags |= SX_BOARD_PRESENT;
2262 func_exit();
2263 return 1;
2267 static int sx_init_drivers(void)
2269 int error;
2271 func_enter();
2273 memset(&sx_driver, 0, sizeof(sx_driver));
2274 sx_driver.magic = TTY_DRIVER_MAGIC;
2275 sx_driver.driver_name = "specialix_sx";
2276 sx_driver.name = "ttyX";
2277 sx_driver.major = SX_NORMAL_MAJOR;
2278 sx_driver.num = sx_nports;
2279 sx_driver.type = TTY_DRIVER_TYPE_SERIAL;
2280 sx_driver.subtype = SX_TYPE_NORMAL;
2281 sx_driver.init_termios = tty_std_termios;
2282 sx_driver.init_termios.c_cflag =
2283 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2284 sx_driver.flags = TTY_DRIVER_REAL_RAW;
2285 sx_driver.refcount = &sx_refcount;
2286 sx_driver.table = sx_table;
2287 sx_driver.termios = sx_termios;
2288 sx_driver.termios_locked = sx_termios_locked;
2290 sx_driver.open = sx_open;
2291 sx_driver.close = gs_close;
2292 sx_driver.write = gs_write;
2293 sx_driver.put_char = gs_put_char;
2294 sx_driver.flush_chars = gs_flush_chars;
2295 sx_driver.write_room = gs_write_room;
2296 sx_driver.chars_in_buffer = gs_chars_in_buffer;
2297 sx_driver.flush_buffer = gs_flush_buffer;
2298 sx_driver.ioctl = sx_ioctl;
2299 sx_driver.throttle = sx_throttle;
2300 sx_driver.unthrottle = sx_unthrottle;
2301 sx_driver.set_termios = gs_set_termios;
2302 sx_driver.stop = gs_stop;
2303 sx_driver.start = gs_start;
2304 sx_driver.hangup = gs_hangup;
2306 sx_callout_driver = sx_driver;
2307 sx_callout_driver.name = "cux";
2308 sx_callout_driver.major = SX_CALLOUT_MAJOR;
2309 sx_callout_driver.subtype = SX_TYPE_CALLOUT;
2311 if ((error = tty_register_driver(&sx_driver))) {
2312 printk(KERN_ERR "sx: Couldn't register sx driver, error = %d\n",
2313 error);
2314 return 1;
2316 if ((error = tty_register_driver(&sx_callout_driver))) {
2317 tty_unregister_driver(&sx_driver);
2318 printk(KERN_ERR "sx: Couldn't register sx callout driver, error = %d\n",
2319 error);
2320 return 1;
2323 func_exit();
2324 return 0;
2328 void * ckmalloc (int size)
2330 void *p;
2332 p = kmalloc(size, GFP_KERNEL);
2333 if (p)
2334 memset(p, 0, size);
2335 return p;
2339 static int sx_init_portstructs (int nboards, int nports)
2341 struct sx_board *board;
2342 struct sx_port *port;
2343 int i, j;
2344 int addr, chans;
2345 int portno;
2347 func_enter();
2349 /* Many drivers statically allocate the maximum number of ports
2350 There is no reason not to allocate them dynamically. Is there? -- REW */
2351 sx_ports = ckmalloc(nports * sizeof (struct sx_port));
2352 if (!sx_ports)
2353 return -ENOMEM;
2355 sx_termios = ckmalloc(nports * sizeof (struct termios *));
2356 if (!sx_termios) {
2357 kfree (sx_ports);
2358 return -ENOMEM;
2361 sx_termios_locked = ckmalloc(nports * sizeof (struct termios *));
2362 if (!sx_termios_locked) {
2363 kfree (sx_ports);
2364 kfree (sx_termios);
2365 return -ENOMEM;
2368 /* Adjust the values in the "driver" */
2369 sx_driver.termios = sx_termios;
2370 sx_driver.termios_locked = sx_termios_locked;
2372 port = sx_ports;
2373 for (i = 0; i < nboards; i++) {
2374 board = &boards[i];
2375 board->ports = port;
2376 for (j=0; j < boards[i].nports;j++) {
2377 sx_dprintk (SX_DEBUG_INIT, "initing port %d\n", j);
2378 port->gs.callout_termios = tty_std_termios;
2379 port->gs.normal_termios = tty_std_termios;
2380 port->gs.magic = SX_MAGIC;
2381 port->gs.close_delay = HZ/2;
2382 port->gs.closing_wait = 30 * HZ;
2383 port->board = board;
2384 port->gs.rd = &sx_real_driver;
2385 #ifdef NEW_WRITE_LOCKING
2386 port->gs.port_write_sem = MUTEX;
2387 #endif
2388 port++;
2392 port = sx_ports;
2393 portno = 0;
2394 for (i = 0; i < nboards; i++) {
2395 board = &boards[i];
2396 board->port_base = portno;
2397 /* Possibly the configuration was rejected. */
2398 sx_dprintk (SX_DEBUG_PROBE, "Board has %d channels\n", board->nports);
2399 if (board->nports <= 0) continue;
2400 /* XXX byteorder ?? */
2401 for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) {
2402 chans = sx_read_module_byte (board, addr, mc_type);
2403 sx_dprintk (SX_DEBUG_PROBE, "Module at %x: %d channels\n", addr, chans);
2404 sx_dprintk (SX_DEBUG_PROBE, "Port at");
2405 for (j=0;j<chans;j++) {
2406 /* The "sx-way" is the way it SHOULD be done. That way in the
2407 future, the firmware may for example pack the structures a bit
2408 more efficient. Neil tells me it isn't going to happen anytime
2409 soon though. */
2410 if (IS_SX_BOARD(board))
2411 port->ch_base = sx_read_module_word (board, addr+j*2, mc_chan_pointer);
2412 else
2413 port->ch_base = addr + 0x100 + 0x300*j;
2415 sx_dprintk (SX_DEBUG_PROBE, " %x", port->ch_base);
2416 port->line = portno++;
2417 port++;
2419 sx_dprintk (SX_DEBUG_PROBE, "\n");
2421 /* This has to be done earlier. */
2422 /* board->flags |= SX_BOARD_INITIALIZED; */
2425 func_exit();
2426 return 0;
2430 static void sx_release_drivers(void)
2432 func_enter();
2433 tty_unregister_driver(&sx_driver);
2434 tty_unregister_driver(&sx_callout_driver);
2435 func_exit();
2438 #ifdef TWO_ZERO
2439 #define PDEV unsigned char pci_bus, unsigned pci_fun
2440 #define pdev pci_bus, pci_fun
2441 #else
2442 #define PDEV struct pci_dev *pdev
2443 #endif
2446 #ifdef CONFIG_PCI
2447 /********************************************************
2448 * Setting bit 17 in the CNTRL register of the PLX 9050 *
2449 * chip forces a retry on writes while a read is pending.*
2450 * This is to prevent the card locking up on Intel Xeon *
2451 * multiprocessor systems with the NX chipset. -- NV *
2452 ********************************************************/
2454 /* Newer cards are produced with this bit set from the configuration
2455 EEprom. As the bit is read/write for the CPU, we can fix it here,
2456 if we detect that it isn't set correctly. -- REW */
2458 void fix_sx_pci (PDEV, struct sx_board *board)
2460 unsigned int hwbase;
2461 unsigned long rebase;
2462 int t;
2464 #define CNTRL_REG_OFFSET 0x14
2466 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
2467 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
2468 rebase = (ulong) ioremap(hwbase, 0x80);
2469 t = readb (rebase + CNTRL_REG_OFFSET*4 + 2);
2470 if (t != 0x06) {
2471 printk (KERN_DEBUG "sx: performing cntrl reg fix: %02x -> 06\n", t);
2472 writeb (0x06, rebase + CNTRL_REG_OFFSET*4+2);
2474 my_iounmap (hwbase, rebase);
2477 #endif
2480 #ifdef MODULE
2481 #define sx_init init_module
2482 #endif
2484 int sx_init(void)
2486 int i;
2487 int found = 0;
2488 struct sx_board *board;
2490 #ifdef CONFIG_PCI
2491 #ifndef TWO_ZERO
2492 struct pci_dev *pdev = NULL;
2493 #else
2494 unsigned char pci_bus, pci_fun;
2495 /* in 2.2.x pdev is a pointer defining a PCI device. In 2.0 its the bus/fn */
2496 #endif
2497 unsigned int tint;
2498 unsigned short tshort;
2499 #endif
2501 func_enter();
2502 sx_dprintk (SX_DEBUG_INIT, "Initing sx module... (sx_debug=%d)\n", sx_debug);
2503 if (abs ((long) (&sx_debug) - sx_debug) < 0x10000) {
2504 printk (KERN_WARNING "sx: sx_debug is an address, instead of a value. "
2505 "Assuming -1.\n");
2506 printk ("(%p)\n", &sx_debug);
2507 sx_debug=-1;
2510 #ifdef CONFIG_PCI
2511 if (pci_present ()) {
2512 #ifndef TWO_ZERO
2513 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
2514 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
2515 pdev))) {
2516 #else
2517 for (i=0;i< SX_NBOARDS;i++) {
2518 if (pcibios_find_device (PCI_VENDOR_ID_SPECIALIX,
2519 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, i,
2520 &pci_bus, &pci_fun)) break;
2521 #endif
2522 /* Specialix has a whole bunch of cards with
2523 0x2000 as the device ID. They say its because
2524 the standard requires it. Stupid standard. */
2525 /* It seems that reading a word doesn't work reliably on 2.0.
2526 Also, reading a non-aligned dword doesn't work. So we read the
2527 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
2528 ourselves */
2529 /* I don't know why the define doesn't work, constant 0x2c does --REW */
2530 pci_read_config_dword (pdev, 0x2c, &tint);
2531 tshort = (tint >> 16) & 0xffff;
2532 sx_dprintk (SX_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
2533 /* sx_dprintk (SX_DEBUG_PROBE, "pdev = %d/%d (%x)\n", pdev, tint); */
2534 if (tshort != 0x0200) {
2535 sx_dprintk (SX_DEBUG_PROBE, "But it's not an SX card (%d)...\n",
2536 tshort);
2537 continue;
2539 board = &boards[found];
2541 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint);
2542 board->hw_base = tint & PCI_BASE_ADDRESS_MEM_MASK;
2543 board->base = (ulong) ioremap(board->hw_base, SX_WINDOW_LEN);
2544 board->irq = get_irq (pdev);
2545 board->flags &= ~SX_BOARD_TYPE;
2546 board->flags |= SX_PCI_BOARD;
2548 sx_dprintk (SX_DEBUG_PROBE, "Got a specialix card: %x/%x(%d).\n",
2549 tint, boards[found].base, board->irq);
2551 if (probe_sx (board)) {
2552 found++;
2553 fix_sx_pci (pdev, board);
2554 } else
2555 my_iounmap (board->hw_base, board->base);
2558 #endif
2560 for (i=0;i<NR_SX_ADDRS;i++) {
2561 board = &boards[found];
2562 board->hw_base = sx_probe_addrs[i];
2563 board->base = (ulong) ioremap(board->hw_base, SX_WINDOW_LEN);
2564 board->flags &= ~SX_BOARD_TYPE;
2565 board->flags |= SX_ISA_BOARD;
2566 board->irq = sx_irqmask?-1:0;
2568 if (probe_sx (board)) {
2569 found++;
2570 } else {
2571 my_iounmap (board->hw_base, board->base);
2575 for (i=0;i<NR_SI_ADDRS;i++) {
2576 board = &boards[found];
2577 board->hw_base = si_probe_addrs[i];
2578 board->base = (ulong) ioremap(board->hw_base, SI2_ISA_WINDOW_LEN);
2579 board->flags &= ~SX_BOARD_TYPE;
2580 board->flags |= SI_ISA_BOARD;
2581 board->irq = sx_irqmask ?-1:0;
2583 if (probe_si (board)) {
2584 found++;
2585 } else {
2586 my_iounmap (board->hw_base, board->base);
2590 if (found) {
2591 printk (KERN_INFO "sx: total of %d boards detected.\n", found);
2593 if (misc_register(&sx_fw_device) < 0) {
2594 printk(KERN_ERR "SX: Unable to register firmware loader driver.\n");
2595 return -EIO;
2599 func_exit();
2600 return found?0:-EIO;
2605 void cleanup_module(void)
2607 int i;
2608 struct sx_board *board;
2610 func_enter();
2611 for (i = 0; i < SX_NBOARDS; i++) {
2612 board = &boards[i];
2613 if (board->flags & SX_BOARD_INITIALIZED) {
2614 sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up board at %x\n", board->base);
2615 /* The board should stop messing with us.
2616 (actually I mean the interrupt) */
2617 sx_reset (board);
2618 if ((board->irq) && (board->flags & SX_IRQ_ALLOCATED))
2619 free_irq (board->irq, board);
2621 /* It is safe/allowed to del_timer a non-active timer */
2622 del_timer (& board->timer);
2623 my_iounmap (board->hw_base, board->base);
2626 if (misc_deregister(&sx_fw_device) < 0) {
2627 printk (KERN_INFO "sx: couldn't deregister firmware loader device\n");
2629 sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up drivers (%d)\n", sx_initialized);
2630 if (sx_initialized)
2631 sx_release_drivers ();
2633 kfree (sx_ports);
2634 kfree (sx_termios);
2635 kfree (sx_termios_locked);
2636 func_exit();
2640 #ifdef DEBUG
2641 void my_hd (unsigned char *addr, int len)
2643 int i, j, ch;
2645 for (i=0;i<len;i+=16) {
2646 printk ("%08x ", (int) addr+i);
2647 for (j=0;j<16;j++) {
2648 printk ("%02x %s", addr[j+i], (j==7)?" ":"");
2650 for (j=0;j<16;j++) {
2651 ch = addr[j+i];
2652 printk ("%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
2654 printk ("\n");
2657 #endif
2659 #ifdef MODULE
2660 #undef func_enter
2661 #undef func_exit
2663 #include "generic_serial.c"
2664 #endif
2668 * Anybody who knows why this doesn't work for me, please tell me -- REW.
2669 * Snatched from scsi.c (fixed one spelling error):
2670 * Overrides for Emacs so that we follow Linus' tabbing style.
2671 * Emacs will notice this stuff at the end of the file and automatically
2672 * adjust the settings for this buffer only. This must remain at the end
2673 * of the file.
2674 * ---------------------------------------------------------------------------
2675 * Local variables:
2676 * c-indent-level: 4
2677 * c-brace-imaginary-offset: 0
2678 * c-brace-offset: -4
2679 * c-argdecl-indent: 4
2680 * c-label-offset: -4
2681 * c-continued-statement-offset: 4
2682 * c-continued-brace-offset: 0
2683 * indent-tabs-mode: nil
2684 * tab-width: 8
2685 * End: