aa23b1cba7c975f255a887cd021bfc13253dcda9
[linux-2.6.git] / drivers / char / rio / rio_linux.c
1
2 /* rio_linux.c -- Linux driver for the Specialix RIO series cards. 
3  *
4  *
5  *   (C) 1999 R.E.Wolff@BitWizard.nl
6  *
7  * Specialix pays for the development and support of this driver.
8  * Please DO contact support@specialix.co.uk if you require
9  * support. But please read the documentation (rio.txt) first.
10  *
11  *
12  *
13  *      This program is free software; you can redistribute it and/or
14  *      modify it under the terms of the GNU General Public License as
15  *      published by the Free Software Foundation; either version 2 of
16  *      the License, or (at your option) any later version.
17  *
18  *      This program is distributed in the hope that it will be
19  *      useful, but WITHOUT ANY WARRANTY; without even the implied
20  *      warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21  *      PURPOSE.  See the GNU General Public License for more details.
22  *
23  *      You should have received a copy of the GNU General Public
24  *      License along with this program; if not, write to the Free
25  *      Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
26  *      USA.
27  *
28  * Revision history:
29  * $Log: rio.c,v $
30  * Revision 1.1  1999/07/11 10:13:54  wolff
31  * Initial revision
32  *
33  * */
34
35
36 #define RCS_ID "$Id: rio.c,v 1.1 1999/07/11 10:13:54 wolff Exp wolff $"
37 #define RCS_REV "$Revision: 1.1 $"
38
39
40 #include <linux/module.h>
41 #include <linux/config.h> 
42 #include <linux/kdev_t.h>
43 #include <asm/io.h>
44 #include <linux/kernel.h>
45 #include <linux/sched.h>
46 #include <linux/ioport.h>
47 #include <linux/interrupt.h>
48 #include <linux/errno.h>
49 #include <linux/tty.h>
50 #include <linux/tty_flip.h>
51 #include <linux/mm.h>
52 #include <linux/serial.h>
53 #include <linux/fcntl.h>
54 #include <linux/major.h>
55 #include <linux/delay.h>
56 #include <linux/pci.h>
57 #include <linux/slab.h>
58 #include <linux/miscdevice.h>
59 #include <linux/init.h>
60
61 #include <linux/generic_serial.h>
62 #include <asm/uaccess.h>
63
64 #if BITS_PER_LONG != 32
65 #  error FIXME: this driver only works on 32-bit platforms
66 #endif
67
68 #include "linux_compat.h"
69 #include "typdef.h"
70 #include "pkt.h"
71 #include "daemon.h"
72 #include "rio.h"
73 #include "riospace.h"
74 #include "top.h"
75 #include "cmdpkt.h"
76 #include "map.h"
77 #include "riotypes.h"
78 #include "rup.h"
79 #include "port.h"
80 #include "riodrvr.h"
81 #include "rioinfo.h"
82 #include "func.h"
83 #include "errors.h"
84 #include "pci.h"
85
86 #include "parmmap.h"
87 #include "unixrup.h"
88 #include "board.h"
89 #include "host.h"
90 #include "error.h"
91 #include "phb.h"
92 #include "link.h"
93 #include "cmdblk.h"
94 #include "route.h"
95 #include "control.h"
96 #include "cirrus.h"
97 #include "rioioctl.h"
98 #include "param.h"
99 #include "list.h"
100 #include "sam.h"
101 #include "protsts.h"
102 #include "rioboard.h"
103
104
105 #include "rio_linux.h"
106
107 /* I don't think that this driver can handle more than 512 ports on
108 one machine.  Specialix specifies max 4 boards in one machine. I don't
109 know why. If you want to try anyway you'll have to increase the number
110 of boards in rio.h.  You'll have to allocate more majors if you need
111 more than 512 ports.... */
112
113 #ifndef RIO_NORMAL_MAJOR0
114 /* This allows overriding on the compiler commandline, or in a "major.h" 
115    include or something like that */
116 #define RIO_NORMAL_MAJOR0  154
117 #define RIO_NORMAL_MAJOR1  156
118 #endif
119
120 #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
121 #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
122 #endif
123
124 #ifndef RIO_WINDOW_LEN 
125 #define RIO_WINDOW_LEN 0x10000
126 #endif
127
128
129 /* Configurable options: 
130    (Don't be too sure that it'll work if you toggle them) */
131
132 /* Am I paranoid or not ? ;-) */
133 #undef RIO_PARANOIA_CHECK
134
135
136 /* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
137    Hz, but it is user configurable. I don't recommend going above 1000
138    Hz. The interrupt ratelimit might trigger if the interrupt is
139    shared with a very active other device. 
140    undef this if you want to disable the check....
141 */
142 #define IRQ_RATE_LIMIT 200
143
144 #if 0
145 /* Not implemented */
146 /* 
147  * The following defines are mostly for testing purposes. But if you need
148  * some nice reporting in your syslog, you can define them also.
149  */
150 #define RIO_REPORT_FIFO
151 #define RIO_REPORT_OVERRUN
152 #endif 
153
154
155 /* These constants are derived from SCO Source */
156 static struct Conf
157 RIOConf =
158 {
159   /* locator */         "RIO Config here",
160   /* startuptime */     HZ*2,           /* how long to wait for card to run */
161   /* slowcook */        0,              /* TRUE -> always use line disc. */
162   /* intrpolltime */    1,              /* The frequency of OUR polls */
163   /* breakinterval */   25,             /* x10 mS XXX: units seem to be 1ms not 10! -- REW*/
164   /* timer */           10,             /* mS */
165   /* RtaLoadBase */     0x7000,
166   /* HostLoadBase */    0x7C00,
167   /* XpHz */            5,              /* number of Xprint hits per second */
168   /* XpCps */           120,            /* Xprint characters per second */
169   /* XpOn */            "\033d#",       /* start Xprint for a wyse 60 */
170   /* XpOff */           "\024",         /* end Xprint for a wyse 60 */
171   /* MaxXpCps */        2000,           /* highest Xprint speed */
172   /* MinXpCps */        10,             /* slowest Xprint speed */
173   /* SpinCmds */        1,              /* non-zero for mega fast boots */
174   /* First Addr */      0x0A0000,       /* First address to look at */
175   /* Last Addr */       0xFF0000,       /* Last address looked at */
176   /* BufferSize */      1024,           /* Bytes per port of buffering */
177   /* LowWater */        256,            /* how much data left before wakeup */
178   /* LineLength */      80,             /* how wide is the console? */
179   /* CmdTimeout */      HZ,             /* how long a close command may take */
180 };
181
182
183
184
185 /* Function prototypes */
186
187 static void rio_disable_tx_interrupts (void * ptr); 
188 static void rio_enable_tx_interrupts (void * ptr); 
189 static void rio_disable_rx_interrupts (void * ptr); 
190 static void rio_enable_rx_interrupts (void * ptr); 
191 static int  rio_get_CD (void * ptr); 
192 static void rio_shutdown_port (void * ptr);
193 static int  rio_set_real_termios (void  *ptr);
194 static void rio_hungup (void  *ptr);
195 static void rio_close (void  *ptr);
196 static int rio_chars_in_buffer (void * ptr);
197 static int rio_fw_ioctl (struct inode *inode, struct file *filp,
198                          unsigned int cmd, unsigned long arg);
199 static int rio_init_drivers(void);
200
201 void my_hd (void *addr, int len);
202
203 static struct tty_driver *rio_driver, *rio_driver2;
204
205 /* The name "p" is a bit non-descript. But that's what the rio-lynxos
206 sources use all over the place. */
207 struct rio_info *p;
208
209 /* struct rio_board boards[RIO_HOSTS]; */
210 struct rio_port *rio_ports;
211
212 int rio_initialized;
213 int rio_nports;
214 int rio_debug;
215
216
217 /* You can have the driver poll your card. 
218     - Set rio_poll to 1 to poll every timer tick (10ms on Intel). 
219       This is used when the card cannot use an interrupt for some reason.
220 */
221 int rio_poll = 1;
222
223
224 /* These are the only open spaces in my computer. Yours may have more
225    or less.... */
226 int rio_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000};
227
228 #define NR_RIO_ADDRS (sizeof(rio_probe_addrs)/sizeof (int))
229
230
231 /* Set the mask to all-ones. This alas, only supports 32 interrupts. 
232    Some architectures may need more. -- Changed to LONG to
233    support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
234 long rio_irqmask = -1;
235
236 MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
237 MODULE_DESCRIPTION("RIO driver");
238 MODULE_LICENSE("GPL");
239 module_param(rio_poll, int, 0);
240 module_param(rio_debug, int, 0644);
241 module_param(rio_irqmask, long, 0);
242
243 static struct real_driver rio_real_driver = {
244   rio_disable_tx_interrupts,
245   rio_enable_tx_interrupts,
246   rio_disable_rx_interrupts,
247   rio_enable_rx_interrupts,
248   rio_get_CD,
249   rio_shutdown_port, 
250   rio_set_real_termios, 
251   rio_chars_in_buffer,
252   rio_close,
253   rio_hungup,
254   NULL
255 };
256
257 /* 
258  *  Firmware loader driver specific routines
259  *
260  */
261
262 static struct file_operations rio_fw_fops = {
263         .owner          = THIS_MODULE,
264         .ioctl          = rio_fw_ioctl,
265 };
266
267 struct miscdevice rio_fw_device = {
268         RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
269 };
270
271
272
273
274
275 #ifdef RIO_PARANOIA_CHECK
276
277 /* This doesn't work. Who's paranoid around here? Not me! */
278
279 static inline int rio_paranoia_check(struct rio_port const * port,
280                                     char *name, const char *routine)
281 {
282
283   static const char *badmagic =
284     KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
285   static const char *badinfo =
286     KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
287  
288   if (!port) {
289     printk (badinfo, name, routine);
290     return 1;
291   }
292   if (port->magic != RIO_MAGIC) {
293     printk (badmagic, name, routine);
294     return 1;
295   }
296
297   return 0;
298 }
299 #else
300 #define rio_paranoia_check(a,b,c) 0
301 #endif
302
303
304 #ifdef DEBUG
305 void my_hd (void *ad, int len)
306 {
307   int i, j, ch;
308   unsigned char *addr = ad;
309   
310   for (i=0;i<len;i+=16) {
311     rio_dprintk (RIO_DEBUG_PARAM, "%08x ", (int) addr+i);
312     for (j=0;j<16;j++) {
313       rio_dprintk (RIO_DEBUG_PARAM, "%02x %s", addr[j+i], (j==7)?" ":"");
314     }
315     for (j=0;j<16;j++) {
316       ch = addr[j+i];
317       rio_dprintk (RIO_DEBUG_PARAM, "%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
318     }
319     rio_dprintk (RIO_DEBUG_PARAM, "\n");
320   }
321 }
322 #else
323 #define my_hd(ad,len) do{/* nothing*/ } while (0)
324 #endif
325
326
327 /* Delay a number of jiffies, allowing a signal to interrupt */ 
328 int RIODelay (struct Port *PortP, int njiffies)
329 {
330   func_enter ();
331
332   rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);  
333   msleep_interruptible(jiffies_to_msecs(njiffies));
334   func_exit();
335
336   if (signal_pending(current))
337     return RIO_FAIL;
338   else
339     return !RIO_FAIL;
340 }
341
342
343 /* Delay a number of jiffies, disallowing a signal to interrupt */ 
344 int RIODelay_ni (struct Port *PortP, int njiffies)
345 {
346   func_enter ();
347
348   rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);  
349   msleep(jiffies_to_msecs(njiffies));
350   func_exit();
351   return !RIO_FAIL;
352 }
353
354
355 int rio_minor(struct tty_struct *tty)
356 {
357         return tty->index + (tty->driver == rio_driver) ? 0 : 256;
358 }
359
360
361 int rio_ismodem(struct tty_struct *tty)
362 {
363         return 1;
364 }
365
366
367 void rio_udelay (int usecs)
368 {
369   udelay (usecs);
370 }
371
372 static int rio_set_real_termios (void *ptr)
373 {
374   int rv, modem;
375   struct tty_struct *tty;
376   func_enter();
377
378   tty = ((struct Port *)ptr)->gs.tty;
379
380   modem = rio_ismodem(tty);
381
382   rv = RIOParam( (struct Port *) ptr, CONFIG, modem, 1);
383
384   func_exit ();
385
386   return rv;
387 }
388
389
390 void rio_reset_interrupt (struct Host *HostP)
391 {
392   func_enter();
393
394   switch( HostP->Type ) {
395   case RIO_AT:
396   case RIO_MCA:
397   case RIO_PCI:
398     WBYTE(HostP->ResetInt , 0xff);
399   }
400
401   func_exit();
402 }
403
404
405 static irqreturn_t rio_interrupt (int irq, void *ptr, struct pt_regs *regs)
406 {
407   struct Host *HostP;
408   func_enter ();
409
410   HostP = (struct Host*)ptr; /* &p->RIOHosts[(long)ptr]; */
411   rio_dprintk (RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", 
412                irq, HostP->Ivec); 
413
414   /* AAargh! The order in which to do these things is essential and
415      not trivial. 
416      
417      - Rate limit goes before "recursive". Otherwise a series of
418        recursive calls will hang the machine in the interrupt routine. 
419
420      - hardware twiddling goes before "recursive". Otherwise when we
421        poll the card, and a recursive interrupt happens, we won't
422        ack the card, so it might keep on interrupting us. (especially
423        level sensitive interrupt systems like PCI).
424
425      - Rate limit goes before hardware twiddling. Otherwise we won't
426        catch a card that has gone bonkers.
427
428      - The "initialized" test goes after the hardware twiddling. Otherwise
429        the card will stick us in the interrupt routine again.
430
431      - The initialized test goes before recursive. 
432   */
433
434
435
436 #ifdef IRQ_RATE_LIMIT
437   /* Aaargh! I'm ashamed. This costs more lines-of-code than the
438      actual interrupt routine!. (Well, used to when I wrote that comment) */
439   {
440     static int lastjif;
441     static int nintr=0;
442
443     if (lastjif == jiffies) {
444       if (++nintr > IRQ_RATE_LIMIT) {
445         free_irq (HostP->Ivec, ptr);
446         printk (KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n", 
447                 HostP->Ivec);
448       }
449     } else {
450       lastjif = jiffies;
451       nintr = 0;
452     }
453   }
454 #endif
455   rio_dprintk (RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n"); 
456   if (HostP->Ivec == irq) {
457     /* Tell the card we've noticed the interrupt. */
458     rio_reset_interrupt (HostP);
459   }
460
461   if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
462         return IRQ_HANDLED;
463
464   if (test_and_set_bit (RIO_BOARD_INTR_LOCK, &HostP->locks)) {
465     printk (KERN_ERR "Recursive interrupt! (host %d/irq%d)\n", 
466             (int) ptr, HostP->Ivec);
467     return IRQ_HANDLED;
468   }
469
470   RIOServiceHost(p, HostP, irq);
471
472   rio_dprintk ( RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n", 
473                 (int) ptr, HostP->Type);
474
475   clear_bit (RIO_BOARD_INTR_LOCK, &HostP->locks);
476   rio_dprintk (RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", 
477                irq, HostP->Ivec); 
478   func_exit ();
479   return IRQ_HANDLED;
480 }
481
482
483 static void rio_pollfunc (unsigned long data)
484 {
485   func_enter ();
486
487   rio_interrupt (0, &p->RIOHosts[data], NULL);
488   p->RIOHosts[data].timer.expires = jiffies + rio_poll;
489   add_timer (&p->RIOHosts[data].timer);
490
491   func_exit ();
492 }
493
494
495 /* ********************************************************************** *
496  *                Here are the routines that actually                     *
497  *              interface with the generic_serial driver                  *
498  * ********************************************************************** */
499
500 /* Ehhm. I don't know how to fiddle with interrupts on the Specialix 
501    cards. ....   Hmm. Ok I figured it out. You don't.  -- REW */
502
503 static void rio_disable_tx_interrupts (void * ptr) 
504 {
505   func_enter();
506
507   /*  port->gs.flags &= ~GS_TX_INTEN; */
508
509   func_exit();
510 }
511
512
513 static void rio_enable_tx_interrupts (void * ptr) 
514 {
515   struct Port *PortP = ptr;
516   /* int hn; */
517
518   func_enter();
519
520   /* hn = PortP->HostP - p->RIOHosts;
521
522      rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
523      rio_interrupt (-1,(void *) hn, NULL); */
524
525   RIOTxEnable((char *) PortP);
526
527   /* 
528    * In general we cannot count on "tx empty" interrupts, although
529    * the interrupt routine seems to be able to tell the difference. 
530    */
531   PortP->gs.flags &= ~GS_TX_INTEN;
532
533   func_exit();
534 }
535
536
537 static void rio_disable_rx_interrupts (void * ptr) 
538 {
539   func_enter();
540   func_exit();
541 }
542
543 static void rio_enable_rx_interrupts (void * ptr) 
544 {
545   /*  struct rio_port *port = ptr; */
546   func_enter();
547   func_exit();
548 }
549
550
551 /* Jeez. Isn't this simple?  */
552 static int rio_get_CD (void * ptr) 
553 {
554   struct Port *PortP = ptr;
555   int rv;
556
557   func_enter();
558   rv = (PortP->ModemState & MSVR1_CD) != 0;
559
560   rio_dprintk (RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
561   
562   func_exit();  
563   return rv;
564 }
565
566
567 /* Jeez. Isn't this simple? Actually, we can sync with the actual port
568    by just pushing stuff into the queue going to the port... */
569 static int rio_chars_in_buffer (void * ptr) 
570 {
571   func_enter();
572
573   func_exit();  
574   return 0;
575 }
576
577
578 /* Nothing special here... */
579 static void rio_shutdown_port (void * ptr) 
580 {
581   struct Port *PortP;
582
583   func_enter();
584
585   PortP = (struct Port *)ptr;
586   PortP->gs.tty = NULL;
587 #if 0
588   port->gs.flags &= ~ GS_ACTIVE;
589   if (!port->gs.tty) {
590     rio_dprintk (RIO_DBUG_TTY, "No tty.\n");
591     return;
592   }
593   if (!port->gs.tty->termios) {
594     rio_dprintk (RIO_DEBUG_TTY, "No termios.\n");
595     return;
596   }
597   if (port->gs.tty->termios->c_cflag & HUPCL) {
598     rio_setsignals (port, 0, 0);
599   }
600 #endif
601
602   func_exit();
603 }
604
605
606 /* I haven't the foggiest why the decrement use count has to happen
607    here. The whole linux serial drivers stuff needs to be redesigned.
608    My guess is that this is a hack to minimize the impact of a bug
609    elsewhere. Thinking about it some more. (try it sometime) Try
610    running minicom on a serial port that is driven by a modularized
611    driver. Have the modem hangup. Then remove the driver module. Then
612    exit minicom.  I expect an "oops".  -- REW */
613 static void rio_hungup (void *ptr)
614 {
615   struct Port *PortP;
616
617   func_enter();
618   
619   PortP = (struct Port *)ptr;
620   PortP->gs.tty = NULL;
621
622   func_exit ();
623 }
624
625
626 /* The standard serial_close would become shorter if you'd wrap it like
627    this. 
628    rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
629  */
630 static void rio_close (void *ptr)
631 {
632   struct Port *PortP;
633
634   func_enter ();
635
636   PortP = (struct Port *)ptr;
637
638   riotclose (ptr);
639
640   if(PortP->gs.count) {
641     printk (KERN_ERR "WARNING port count:%d\n", PortP->gs.count);
642     PortP->gs.count = 0; 
643   }                
644
645   PortP->gs.tty = NULL;
646   func_exit ();
647 }
648
649
650
651 static int rio_fw_ioctl (struct inode *inode, struct file *filp,
652                          unsigned int cmd, unsigned long arg)
653 {
654   int rc = 0;
655   func_enter();
656
657   /* The "dev" argument isn't used. */
658   rc = riocontrol (p, 0, cmd, (void *)arg, capable(CAP_SYS_ADMIN));
659
660   func_exit ();
661   return rc;
662 }
663
664 extern int RIOShortCommand(struct rio_info *p, struct Port *PortP,
665                int command, int len, int arg);
666
667 static int rio_ioctl (struct tty_struct * tty, struct file * filp, 
668                      unsigned int cmd, unsigned long arg)
669 {
670   int rc;
671   struct Port *PortP;
672   int ival;
673
674   func_enter();
675
676   PortP = (struct Port *)tty->driver_data;
677
678   rc  = 0;
679   switch (cmd) {
680 #if 0
681   case TIOCGSOFTCAR:
682     rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
683                   (unsigned int *) arg);
684     break;
685 #endif
686   case TIOCSSOFTCAR:
687     if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
688       tty->termios->c_cflag =
689         (tty->termios->c_cflag & ~CLOCAL) |
690         (ival ? CLOCAL : 0);
691     }
692     break;
693   case TIOCGSERIAL:
694     if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
695                           sizeof(struct serial_struct))) == 0)
696       rc = gs_getserial(&PortP->gs, (struct serial_struct *) arg);
697     break;
698   case TCSBRK:
699     if ( PortP->State & RIO_DELETED ) {
700       rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
701       rc = -EIO;      
702     } else {
703       if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) {
704          rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
705          rc = -EIO;
706       }          
707     }
708     break;
709   case TCSBRKP:
710     if ( PortP->State & RIO_DELETED ) {
711       rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
712       rc = -EIO;      
713     } else {
714       int l;
715       l = arg?arg*100:250;
716       if (l > 255) l = 255;
717       if (RIOShortCommand(p, PortP, SBREAK, 2, arg?arg*100:250) == RIO_FAIL) {
718          rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
719          rc = -EIO;
720       }          
721     }
722     break;
723   case TIOCSSERIAL:
724     if ((rc = verify_area(VERIFY_READ, (void *) arg,
725                           sizeof(struct serial_struct))) == 0)
726       rc = gs_setserial(&PortP->gs, (struct serial_struct *) arg);
727     break;
728 #if 0
729   /*
730    * note: these IOCTLs no longer reach here.  Use
731    * tiocmset/tiocmget driver methods instead.  The
732    * #if 0 disablement predates this comment.
733    */
734   case TIOCMGET:
735     if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
736                           sizeof(unsigned int))) == 0) {
737       ival = rio_getsignals(port);
738       put_user(ival, (unsigned int *) arg);
739     }
740     break;
741   case TIOCMBIS:
742     if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
743       rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : -1),
744                            ((ival & TIOCM_RTS) ? 1 : -1));
745     }
746     break;
747   case TIOCMBIC:
748     if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
749       rio_setsignals(port, ((ival & TIOCM_DTR) ? 0 : -1),
750                            ((ival & TIOCM_RTS) ? 0 : -1));
751     }
752     break;
753   case TIOCMSET:
754     if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
755       rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : 0),
756                            ((ival & TIOCM_RTS) ? 1 : 0));
757     }
758     break;
759 #endif
760   default:
761     rc = -ENOIOCTLCMD;
762     break;
763   }
764   func_exit();
765   return rc;
766 }
767
768
769 /* The throttle/unthrottle scheme for the Specialix card is different
770  * from other drivers and deserves some explanation. 
771  * The Specialix hardware takes care of XON/XOFF
772  * and CTS/RTS flow control itself.  This means that all we have to
773  * do when signalled by the upper tty layer to throttle/unthrottle is
774  * to make a note of it here.  When we come to read characters from the
775  * rx buffers on the card (rio_receive_chars()) we look to see if the
776  * upper layer can accept more (as noted here in rio_rx_throt[]). 
777  * If it can't we simply don't remove chars from the cards buffer. 
778  * When the tty layer can accept chars, we again note that here and when
779  * rio_receive_chars() is called it will remove them from the cards buffer.
780  * The card will notice that a ports buffer has drained below some low
781  * water mark and will unflow control the line itself, using whatever
782  * flow control scheme is in use for that port. -- Simon Allen
783  */
784
785 static void rio_throttle (struct tty_struct * tty)
786 {
787   struct Port *port = (struct Port *)tty->driver_data;
788   
789   func_enter();
790   /* If the port is using any type of input flow
791    * control then throttle the port.
792    */
793
794   if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) {
795     port->State |= RIO_THROTTLE_RX;
796   }
797
798   func_exit();
799 }
800
801
802 static void rio_unthrottle (struct tty_struct * tty)
803 {
804   struct Port *port = (struct Port *)tty->driver_data;
805
806   func_enter();
807   /* Always unthrottle even if flow control is not enabled on
808    * this port in case we disabled flow control while the port
809    * was throttled
810    */
811
812   port->State &= ~RIO_THROTTLE_RX;
813
814   func_exit();
815   return;
816 }
817
818
819
820
821
822 /* ********************************************************************** *
823  *                    Here are the initialization routines.               *
824  * ********************************************************************** */
825
826
827 struct vpd_prom *get_VPD_PROM (struct Host *hp)
828 {
829   static struct vpd_prom vpdp;
830   char *p;
831   int i;
832
833   func_enter();
834   rio_dprintk (RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", 
835               hp->Caddr + RIO_VPD_ROM);
836
837   p = (char *) &vpdp;
838   for (i=0;i< sizeof (struct vpd_prom);i++)
839     *p++ = readb (hp->Caddr+RIO_VPD_ROM + i*2);
840       /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
841
842   /* Terminate the identifier string. 
843      *** requires one extra byte in struct vpd_prom *** */
844   *p++=0; 
845
846   if (rio_debug & RIO_DEBUG_PROBE)
847     my_hd ((char *)&vpdp, 0x20);
848   
849   func_exit();
850
851   return &vpdp;
852 }
853
854 static struct tty_operations rio_ops = {
855         .open  = riotopen,
856         .close = gs_close,
857         .write = gs_write,
858         .put_char = gs_put_char,
859         .flush_chars = gs_flush_chars,
860         .write_room = gs_write_room,
861         .chars_in_buffer = gs_chars_in_buffer,
862         .flush_buffer = gs_flush_buffer,
863         .ioctl = rio_ioctl,
864         .throttle = rio_throttle,
865         .unthrottle = rio_unthrottle,
866         .set_termios = gs_set_termios,
867         .stop = gs_stop,
868         .start = gs_start,
869         .hangup = gs_hangup,
870 };
871
872 static int rio_init_drivers(void)
873 {
874         int error = -ENOMEM;
875
876         rio_driver = alloc_tty_driver(256);
877         if (!rio_driver)
878                 goto out;
879         rio_driver2 = alloc_tty_driver(256);
880         if (!rio_driver2)
881                 goto out1;
882
883         func_enter();
884
885         rio_driver->owner = THIS_MODULE;
886         rio_driver->driver_name = "specialix_rio";
887         rio_driver->name = "ttySR";
888         rio_driver->major = RIO_NORMAL_MAJOR0;
889         rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
890         rio_driver->subtype = SERIAL_TYPE_NORMAL;
891         rio_driver->init_termios = tty_std_termios;
892         rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
893         rio_driver->flags = TTY_DRIVER_REAL_RAW;
894         tty_set_operations(rio_driver, &rio_ops);
895
896         rio_driver2->owner = THIS_MODULE;
897         rio_driver2->driver_name = "specialix_rio";
898         rio_driver2->name = "ttySR";
899         rio_driver2->major = RIO_NORMAL_MAJOR1;
900         rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
901         rio_driver2->subtype = SERIAL_TYPE_NORMAL;
902         rio_driver2->init_termios = tty_std_termios;
903         rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
904         rio_driver2->flags = TTY_DRIVER_REAL_RAW;
905         tty_set_operations(rio_driver2, &rio_ops);
906
907         rio_dprintk (RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
908
909         if ((error = tty_register_driver(rio_driver)))
910                 goto out2;
911         if ((error = tty_register_driver(rio_driver2)))
912                 goto out3;
913         func_exit();
914         return 0;
915 out3:
916         tty_unregister_driver(rio_driver);
917 out2:
918         put_tty_driver(rio_driver2);
919 out1:
920         put_tty_driver(rio_driver);
921 out:
922         printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n",
923              error);
924         return 1;
925 }
926
927
928 static void * ckmalloc (int size)
929 {
930   void *p;
931
932   p = kmalloc(size, GFP_KERNEL);
933   if (p) 
934     memset(p, 0, size);
935   return p;
936 }
937
938
939
940 static int rio_init_datastructures (void)
941 {
942   int i;
943   struct Port *port;
944   func_enter();
945
946   /* Many drivers statically allocate the maximum number of ports
947      There is no reason not to allocate them dynamically. Is there? -- REW */
948   /* However, the RIO driver allows users to configure their first
949      RTA as the ports numbered 504-511. We therefore need to allocate 
950      the whole range. :-(   -- REW */
951   
952 #define RI_SZ   sizeof(struct rio_info)
953 #define HOST_SZ sizeof(struct Host)
954 #define PORT_SZ sizeof(struct Port *)
955 #define TMIO_SZ sizeof(struct termios *)
956   rio_dprintk (RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n", 
957                RI_SZ, 
958                RIO_HOSTS * HOST_SZ,
959                RIO_PORTS * PORT_SZ,
960                RIO_PORTS * TMIO_SZ,
961                RIO_PORTS * TMIO_SZ);
962   
963   if (!(p                  = ckmalloc (              RI_SZ))) goto free0;
964   if (!(p->RIOHosts        = ckmalloc (RIO_HOSTS * HOST_SZ))) goto free1;
965   if (!(p->RIOPortp        = ckmalloc (RIO_PORTS * PORT_SZ))) goto free2;
966   p->RIOConf = RIOConf;
967   rio_dprintk (RIO_DEBUG_INIT, "Got : %p %p %p\n", 
968                p, p->RIOHosts, p->RIOPortp);
969
970 #if 1
971   for (i = 0; i < RIO_PORTS; i++) {
972     port = p->RIOPortp[i] = ckmalloc (sizeof (struct Port));
973     if (!port) {
974       goto free6;
975     }
976     rio_dprintk (RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
977     port->PortNum = i;
978     port->gs.magic = RIO_MAGIC;
979     port->gs.close_delay = HZ/2;
980     port->gs.closing_wait = 30 * HZ;
981     port->gs.rd = &rio_real_driver;
982     port->portSem = SPIN_LOCK_UNLOCKED;
983     /*
984      * Initializing wait queue
985      */
986     init_waitqueue_head(&port->gs.open_wait);
987     init_waitqueue_head(&port->gs.close_wait);
988   }
989 #else
990   /* We could postpone initializing them to when they are configured. */
991 #endif
992
993
994   
995   if (rio_debug & RIO_DEBUG_INIT) {
996     my_hd (&rio_real_driver, sizeof (rio_real_driver));
997   }
998
999   
1000   func_exit();
1001   return 0;
1002
1003  free6:for (i--;i>=0;i--)
1004         kfree (p->RIOPortp[i]);
1005 /*free5:
1006  free4:
1007  free3:*/kfree (p->RIOPortp);
1008  free2:kfree (p->RIOHosts);
1009  free1:
1010   rio_dprintk (RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", 
1011                        p, p->RIOHosts, p->RIOPortp);
1012   kfree(p);                   
1013  free0:
1014   return -ENOMEM;
1015 }
1016
1017 static void  __exit rio_release_drivers(void)
1018 {
1019   func_enter();
1020   tty_unregister_driver(rio_driver2);
1021   tty_unregister_driver(rio_driver);
1022   put_tty_driver(rio_driver2);
1023   put_tty_driver(rio_driver);
1024   func_exit();
1025 }
1026
1027
1028 #ifdef CONFIG_PCI
1029  /* This was written for SX, but applies to RIO too...
1030     (including bugs....)
1031
1032     There is another bit besides Bit 17. Turning that bit off
1033     (on boards shipped with the fix in the eeprom) results in a 
1034     hang on the next access to the card. 
1035  */
1036
1037  /******************************************************** 
1038  * Setting bit 17 in the CNTRL register of the PLX 9050  * 
1039  * chip forces a retry on writes while a read is pending.*
1040  * This is to prevent the card locking up on Intel Xeon  *
1041  * multiprocessor systems with the NX chipset.    -- NV  *
1042  ********************************************************/
1043
1044 /* Newer cards are produced with this bit set from the configuration
1045    EEprom.  As the bit is read/write for the CPU, we can fix it here,
1046    if we detect that it isn't set correctly. -- REW */
1047
1048 void fix_rio_pci (struct pci_dev *pdev)
1049 {
1050   unsigned int hwbase;
1051   unsigned long rebase;
1052   unsigned int t;
1053
1054 #define CNTRL_REG_OFFSET        0x50
1055 #define CNTRL_REG_GOODVALUE     0x18260000
1056
1057   pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
1058   hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
1059   rebase =  (ulong) ioremap(hwbase, 0x80);
1060   t = readl (rebase + CNTRL_REG_OFFSET);
1061   if (t != CNTRL_REG_GOODVALUE) {
1062     printk (KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", 
1063             t, CNTRL_REG_GOODVALUE); 
1064     writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);  
1065   }
1066   iounmap((char*) rebase);
1067 }
1068 #endif
1069
1070
1071 static int __init rio_init(void) 
1072 {
1073   int found = 0;
1074   int i;
1075   struct Host *hp;
1076   int retval;
1077   struct vpd_prom *vpdp;
1078   int okboard;
1079
1080 #ifdef CONFIG_PCI
1081   struct pci_dev *pdev = NULL;
1082   unsigned int tint;
1083   unsigned short tshort;
1084 #endif
1085
1086   func_enter();
1087   rio_dprintk (RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", 
1088                rio_debug);
1089
1090   if (abs ((long) (&rio_debug) - rio_debug) < 0x10000) {
1091     printk (KERN_WARNING "rio: rio_debug is an address, instead of a value. "
1092             "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
1093     rio_debug=-1;
1094   }
1095
1096   if (misc_register(&rio_fw_device) < 0) {
1097     printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
1098     return -EIO;
1099   }
1100
1101   retval = rio_init_datastructures ();
1102   if (retval < 0) {
1103     misc_deregister(&rio_fw_device);
1104     return retval;
1105   }
1106
1107 #ifdef CONFIG_PCI
1108     /* First look for the JET devices: */
1109     while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, 
1110                                     PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, 
1111                                     pdev))) {
1112        if (pci_enable_device(pdev)) continue;
1113
1114       /* Specialix has a whole bunch of cards with
1115          0x2000 as the device ID. They say its because
1116          the standard requires it. Stupid standard. */
1117       /* It seems that reading a word doesn't work reliably on 2.0.
1118          Also, reading a non-aligned dword doesn't work. So we read the
1119          whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
1120          ourselves */
1121       /* I don't know why the define doesn't work, constant 0x2c does --REW */ 
1122       pci_read_config_dword (pdev, 0x2c, &tint);
1123       tshort = (tint >> 16) & 0xffff;
1124       rio_dprintk (RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
1125       if (tshort != 0x0100) {
1126         rio_dprintk (RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", 
1127                     tshort);
1128         continue;
1129       }
1130       rio_dprintk (RIO_DEBUG_PROBE, "cp1\n");
1131
1132       pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint);
1133
1134       hp = &p->RIOHosts[p->RIONumHosts];
1135       hp->PaddrP =  tint & PCI_BASE_ADDRESS_MEM_MASK;
1136       hp->Ivec = pdev->irq;
1137       if (((1 << hp->Ivec) & rio_irqmask) == 0)
1138               hp->Ivec = 0;
1139       hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1140       hp->CardP = (struct DpRam *) hp->Caddr;
1141       hp->Type  = RIO_PCI;
1142       hp->Copy  = rio_pcicopy; 
1143       hp->Mode  = RIO_PCI_BOOT_FROM_RAM;
1144       hp->HostLock = SPIN_LOCK_UNLOCKED;
1145       rio_reset_interrupt (hp);
1146       rio_start_card_running (hp);
1147
1148       rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
1149                    (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
1150                    p->RIOHosts[p->RIONumHosts].Caddr);
1151       if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
1152                         p->RIOHosts[p->RIONumHosts].Caddr, 
1153                         RIO_PCI, 0 ) == RIO_SUCCESS) {
1154               rio_dprintk (RIO_DEBUG_INIT, "Done RIOBoardTest\n");
1155               WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1156               p->RIOHosts[p->RIONumHosts].UniqueNum  =
1157                       ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
1158                       ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
1159                       ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
1160                       ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
1161               rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1162                            p->RIOHosts[p->RIONumHosts].UniqueNum);
1163               
1164               fix_rio_pci (pdev);
1165               p->RIOLastPCISearch = RIO_SUCCESS;
1166               p->RIONumHosts++;
1167               found++;
1168       } else {
1169               iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
1170       }
1171     }
1172     
1173     /* Then look for the older PCI card.... : */
1174
1175   /* These older PCI cards have problems (only byte-mode access is
1176      supported), which makes them a bit awkward to support. 
1177      They also have problems sharing interrupts. Be careful. 
1178      (The driver now refuses to share interrupts for these
1179      cards. This should be sufficient).
1180   */
1181
1182     /* Then look for the older RIO/PCI devices: */
1183     while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, 
1184                                     PCI_DEVICE_ID_SPECIALIX_RIO, 
1185                                     pdev))) {
1186        if (pci_enable_device(pdev)) continue;
1187
1188 #ifdef CONFIG_RIO_OLDPCI
1189       pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint);
1190
1191       hp = &p->RIOHosts[p->RIONumHosts];
1192       hp->PaddrP =  tint & PCI_BASE_ADDRESS_MEM_MASK;
1193       hp->Ivec = pdev->irq;
1194       if (((1 << hp->Ivec) & rio_irqmask) == 0) 
1195         hp->Ivec = 0;
1196       hp->Ivec |= 0x8000; /* Mark as non-sharable */
1197       hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1198       hp->CardP = (struct DpRam *) hp->Caddr;
1199       hp->Type  = RIO_PCI;
1200       hp->Copy  = rio_pcicopy;
1201       hp->Mode  = RIO_PCI_BOOT_FROM_RAM;
1202       hp->HostLock = SPIN_LOCK_UNLOCKED;
1203
1204       rio_dprintk (RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1205       rio_dprintk (RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
1206
1207       rio_reset_interrupt (hp);
1208       rio_start_card_running (hp);
1209        rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
1210                    (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
1211                    p->RIOHosts[p->RIONumHosts].Caddr);
1212       if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
1213                         p->RIOHosts[p->RIONumHosts].Caddr, 
1214                         RIO_PCI, 0 ) == RIO_SUCCESS) {
1215         WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1216         p->RIOHosts[p->RIONumHosts].UniqueNum  =
1217           ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
1218           ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
1219           ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
1220           ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
1221         rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1222                    p->RIOHosts[p->RIONumHosts].UniqueNum);
1223
1224         p->RIOLastPCISearch = RIO_SUCCESS;
1225         p->RIONumHosts++;
1226         found++;
1227       } else {
1228         iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
1229       }
1230 #else
1231       printk (KERN_ERR "Found an older RIO PCI card, but the driver is not "
1232               "compiled to support it.\n");
1233 #endif
1234     }
1235 #endif /* PCI */
1236
1237   /* Now probe for ISA cards... */
1238   for (i=0;i<NR_RIO_ADDRS;i++) {
1239     hp = &p->RIOHosts[p->RIONumHosts];
1240     hp->PaddrP = rio_probe_addrs[i];
1241     /* There was something about the IRQs of these cards. 'Forget what.--REW */
1242     hp->Ivec = 0;
1243     hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1244     hp->CardP = (struct DpRam *) hp->Caddr;
1245     hp->Type = RIO_AT;
1246     hp->Copy = rio_pcicopy; /* AT card PCI???? - PVDL
1247                              * -- YES! this is now a normal copy. Only the 
1248                              * old PCI card uses the special PCI copy. 
1249                              * Moreover, the ISA card will work with the 
1250                              * special PCI copy anyway. -- REW */
1251     hp->Mode = 0;
1252     hp->HostLock = SPIN_LOCK_UNLOCKED;
1253
1254     vpdp = get_VPD_PROM (hp);
1255     rio_dprintk (RIO_DEBUG_PROBE, "Got VPD ROM\n");
1256     okboard = 0;
1257     if ((strncmp (vpdp->identifier, RIO_ISA_IDENT, 16) == 0) ||
1258         (strncmp (vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) ||
1259         (strncmp (vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) {
1260       /* Board is present... */
1261       if (RIOBoardTest (hp->PaddrP, 
1262                         hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) {
1263         /* ... and feeling fine!!!! */
1264         rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1265                    p->RIOHosts[p->RIONumHosts].UniqueNum);
1266         if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {        
1267           rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n",
1268                        p->RIONumHosts, 
1269                        p->RIOHosts[p->RIONumHosts-1].UniqueNum);
1270           okboard++;
1271           found++;
1272         }
1273       }
1274
1275     if (!okboard)
1276       iounmap ((char*) (hp->Caddr));
1277     }
1278   }
1279
1280
1281   for (i=0;i<p->RIONumHosts;i++) {
1282     hp = &p->RIOHosts[i];
1283     if (hp->Ivec) {
1284       int mode = SA_SHIRQ;
1285       if (hp->Ivec & 0x8000) {mode = 0; hp->Ivec &= 0x7fff;}
1286       rio_dprintk (RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp,hp->Ivec, hp->Mode);
1287       retval = request_irq (hp->Ivec, rio_interrupt, mode, "rio", hp);
1288       rio_dprintk (RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1289       if (retval) {
1290               printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1291               hp->Ivec = 0;
1292       }
1293       rio_dprintk (RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1294       if (hp->Ivec != 0){
1295               rio_dprintk (RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n"); 
1296               hp->Mode |= RIO_PCI_INT_ENABLE;
1297       } else
1298               hp->Mode &= !RIO_PCI_INT_ENABLE;
1299       rio_dprintk (RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1300       rio_start_card_running (hp);
1301     }
1302     /* Init the timer "always" to make sure that it can safely be 
1303        deleted when we unload... */
1304
1305     init_timer (&hp->timer);
1306     if (!hp->Ivec) {
1307       rio_dprintk (RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", 
1308                    rio_poll);
1309       hp->timer.data = i;
1310       hp->timer.function = rio_pollfunc;
1311       hp->timer.expires = jiffies + rio_poll;
1312       add_timer (&hp->timer);
1313     }
1314   }
1315
1316   if (found) {
1317     rio_dprintk (RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1318     rio_init_drivers ();
1319   } else {
1320     /* deregister the misc device we created earlier */
1321     misc_deregister(&rio_fw_device);
1322   }
1323
1324   func_exit();
1325   return found?0:-EIO;
1326 }
1327
1328
1329 static void __exit rio_exit (void)
1330 {
1331   int i; 
1332   struct Host *hp;
1333   
1334   func_enter();
1335
1336   for (i=0,hp=p->RIOHosts;i<p->RIONumHosts;i++, hp++) {
1337     RIOHostReset (hp->Type, hp->CardP, hp->Slot);
1338     if (hp->Ivec) {
1339       free_irq (hp->Ivec, hp);
1340       rio_dprintk (RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1341     }
1342     /* It is safe/allowed to del_timer a non-active timer */
1343     del_timer (&hp->timer);
1344   }
1345
1346   if (misc_deregister(&rio_fw_device) < 0) {
1347     printk (KERN_INFO "rio: couldn't deregister control-device\n");
1348   }
1349
1350
1351   rio_dprintk (RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
1352
1353   rio_release_drivers ();
1354
1355   /* Release dynamically allocated memory */
1356   kfree (p->RIOPortp);
1357   kfree (p->RIOHosts);
1358   kfree (p);
1359
1360   func_exit();
1361 }
1362
1363 module_init(rio_init);
1364 module_exit(rio_exit);
1365
1366 /*
1367  * Anybody who knows why this doesn't work for me, please tell me -- REW.
1368  * Snatched from scsi.c (fixed one spelling error):
1369  * Overrides for Emacs so that we follow Linus' tabbing style.
1370  * Emacs will notice this stuff at the end of the file and automatically
1371  * adjust the settings for this buffer only.  This must remain at the end
1372  * of the file.
1373  * ---------------------------------------------------------------------------
1374  * Local Variables:
1375  * c-indent-level: 4
1376  * c-brace-imaginary-offset: 0
1377  * c-brace-offset: -4
1378  * c-argdecl-indent: 4
1379  * c-label-offset: -4
1380  * c-continued-statement-offset: 4
1381  * c-continued-brace-offset: 0
1382  * indent-tabs-mode: nil
1383  * tab-width: 8
1384  * End:
1385  */
1386