import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / drivers / sbus / char / aurora.c
1 /*      $Id: aurora.c,v 1.18.2.1 2002/02/04 22:37:43 davem Exp $
2  *      linux/drivers/sbus/char/aurora.c -- Aurora multiport driver
3  *
4  *      Copyright (c) 1999 by Oliver Aldulea (oli at bv dot ro)
5  *
6  *      This code is based on the RISCom/8 multiport serial driver written
7  *      by Dmitry Gorodchanin (pgmdsg@ibi.com), based on the Linux serial
8  *      driver, written by Linus Torvalds, Theodore T'so and others.
9  *      The Aurora multiport programming info was obtained mainly from the
10  *      Cirrus Logic CD180 documentation (available on the web), and by
11  *      doing heavy tests on the board. Many thanks to Eddie C. Dost for the
12  *      help on the sbus interface.
13  *
14  *      This program is free software; you can redistribute it and/or modify
15  *      it under the terms of the GNU General Public License as published by
16  *      the Free Software Foundation; either version 2 of the License, or
17  *      (at your option) any later version.
18  *
19  *      This program is distributed in the hope that it will be useful,
20  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *      GNU General Public License for more details.
23  *
24  *      You should have received a copy of the GNU General Public License
25  *      along with this program; if not, write to the Free Software
26  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  *
28  *      Revision 1.0
29  *
30  *      This is the first public release.
31  *
32  *      Most of the information you need is in the aurora.h file. Please
33  *      read that file before reading this one.
34  *
35  *      Several parts of the code do not have comments yet.
36  * 
37  * n.b.  The board can support 115.2 bit rates, but only on a few
38  * ports. The total badwidth of one chip (ports 0-7 or 8-15) is equal
39  * to OSC_FREQ div 16. In case of my board, each chip can take 6
40  * channels of 115.2 kbaud.  This information is not well-tested.
41  * 
42  * Fixed to use tty_get_baud_rate().
43  *   Theodore Ts'o <tytso@mit.edu>, 2001-Oct-12
44  */
45
46 #include <linux/module.h>
47
48 #include <linux/errno.h>
49 #include <linux/sched.h>
50 #ifdef AURORA_INT_DEBUG
51 #include <linux/timer.h>
52 #endif
53 #include <linux/interrupt.h>
54 #include <linux/tty.h>
55 #include <linux/tty_flip.h>
56 #include <linux/major.h>
57 #include <linux/string.h>
58 #include <linux/fcntl.h>
59 #include <linux/mm.h>
60 #include <linux/kernel.h>
61 #include <linux/init.h>
62 #include <linux/tqueue.h>
63 #include <linux/delay.h>
64
65 #include <asm/io.h>
66 #include <asm/irq.h>
67 #include <asm/oplib.h>
68 #include <asm/system.h>
69 #include <asm/segment.h>
70 #include <asm/bitops.h>
71 #include <asm/kdebug.h>
72 #include <asm/sbus.h>
73 #include <asm/uaccess.h>
74
75 #include "aurora.h"
76 #include "cd180.h"
77
78 unsigned char irqs[4] = {
79         0, 0, 0, 0
80 };
81
82 #ifdef AURORA_INT_DEBUG
83 int irqhit=0;
84 #endif
85
86 #ifndef MIN
87 #define MIN(a,b) ((a) < (b) ? (a) : (b))
88 #endif
89
90 #define AURORA_TYPE_NORMAL      1
91
92 static struct tty_driver aurora_driver;
93 static struct Aurora_board aurora_board[AURORA_NBOARD] = {
94         {0,},
95 };
96
97 static struct Aurora_port aurora_port[AURORA_TNPORTS] =  {
98         { 0, },
99 };
100
101 /* no longer used. static struct Aurora_board * IRQ_to_board[16] = { NULL, } ;*/
102 static unsigned char * tmp_buf = NULL;
103 static DECLARE_MUTEX(tmp_buf_sem);
104 static int    aurora_refcount = 0;
105 static struct tty_struct * aurora_table[AURORA_TNPORTS] = { NULL, };
106 static struct termios * aurora_termios[AURORA_TNPORTS] = { NULL, };
107 static struct termios * aurora_termios_locked[AURORA_TNPORTS] = { NULL, };
108
109 DECLARE_TASK_QUEUE(tq_aurora);
110
111 static inline int aurora_paranoia_check(struct Aurora_port const * port,
112                                     kdev_t device, const char *routine)
113 {
114 #ifdef AURORA_PARANOIA_CHECK
115         static const char *badmagic =
116                 KERN_DEBUG "aurora: Warning: bad aurora port magic number for device %s in %s\n";
117         static const char *badinfo =
118                 KERN_DEBUG "aurora: Warning: null aurora port for device %s in %s\n";
119
120         if (!port) {
121                 printk(badinfo, kdevname(device), routine);
122                 return 1;
123         }
124         if (port->magic != AURORA_MAGIC) {
125                 printk(badmagic, kdevname(device), routine);
126                 return 1;
127         }
128 #endif
129         return 0;
130 }
131
132 /*
133  * 
134  *  Service functions for aurora driver.
135  * 
136  */
137
138 /* Get board number from pointer */
139 static inline int board_No (struct Aurora_board const * bp)
140 {
141         return bp - aurora_board;
142 }
143
144 /* Get port number from pointer */
145 static inline int port_No (struct Aurora_port const * port)
146 {
147         return AURORA_PORT(port - aurora_port); 
148 }
149
150 /* Get pointer to board from pointer to port */
151 static inline struct Aurora_board * port_Board(struct Aurora_port const * port)
152 {
153         return &aurora_board[AURORA_BOARD(port - aurora_port)];
154 }
155
156 /* Wait for Channel Command Register ready */
157 static inline void aurora_wait_CCR(struct aurora_reg128 * r)
158 {
159         unsigned long delay;
160
161 #ifdef AURORA_DEBUG
162 printk("aurora_wait_CCR\n");
163 #endif
164         /* FIXME: need something more descriptive than 100000 :) */
165         for (delay = 100000; delay; delay--) 
166                 if (!sbus_readb(&r->r[CD180_CCR]))
167                         return;
168         printk(KERN_DEBUG "aurora: Timeout waiting for CCR.\n");
169 }
170
171 /*
172  *  aurora probe functions.
173  */
174
175 /* Must be called with enabled interrupts */
176 static inline void aurora_long_delay(unsigned long delay)
177 {
178         unsigned long i;
179
180 #ifdef AURORA_DEBUG
181         printk("aurora_long_delay: start\n");
182 #endif
183         for (i = jiffies + delay; time_before(jiffies, i); ) ;
184 #ifdef AURORA_DEBUG
185         printk("aurora_long_delay: end\n");
186 #endif
187 }
188
189 /* Reset and setup CD180 chip */
190 static int aurora_init_CD180(struct Aurora_board * bp, int chip)
191 {
192         unsigned long flags;
193         int id;
194         
195 #ifdef AURORA_DEBUG
196         printk("aurora_init_CD180: start %d:%d\n",
197                board_No(bp), chip);
198 #endif
199         save_flags(flags); cli();
200         sbus_writeb(0, &bp->r[chip]->r[CD180_CAR]);
201         sbus_writeb(0, &bp->r[chip]->r[CD180_GSVR]);
202
203         /* Wait for CCR ready        */
204         aurora_wait_CCR(bp->r[chip]);
205
206         /* Reset CD180 chip          */
207         sbus_writeb(CCR_HARDRESET, &bp->r[chip]->r[CD180_CCR]);
208         udelay(1);
209         sti();
210         id=1000;
211         while((--id) &&
212               (sbus_readb(&bp->r[chip]->r[CD180_GSVR])!=0xff))udelay(100);
213         if(!id) {
214                 printk(KERN_ERR "aurora%d: Chip %d failed init.\n",
215                        board_No(bp), chip);
216                 restore_flags(flags);
217                 return(-1);
218         }
219         cli();
220         sbus_writeb((board_No(bp)<<5)|((chip+1)<<3),
221                     &bp->r[chip]->r[CD180_GSVR]); /* Set ID for this chip      */
222         sbus_writeb(0x80|bp->ACK_MINT,
223                     &bp->r[chip]->r[CD180_MSMR]); /* Prio for modem intr       */
224         sbus_writeb(0x80|bp->ACK_TINT,
225                     &bp->r[chip]->r[CD180_TSMR]); /* Prio for transmitter intr */
226         sbus_writeb(0x80|bp->ACK_RINT,
227                     &bp->r[chip]->r[CD180_RSMR]); /* Prio for receiver intr    */
228         /* Setting up prescaler. We need 4 tick per 1 ms */
229         sbus_writeb((bp->oscfreq/(1000000/AURORA_TPS)) >> 8,
230                     &bp->r[chip]->r[CD180_PPRH]);
231         sbus_writeb((bp->oscfreq/(1000000/AURORA_TPS)) & 0xff,
232                     &bp->r[chip]->r[CD180_PPRL]);
233
234         sbus_writeb(SRCR_AUTOPRI|SRCR_GLOBPRI,
235                     &bp->r[chip]->r[CD180_SRCR]);
236
237         id = sbus_readb(&bp->r[chip]->r[CD180_GFRCR]);
238         printk(KERN_INFO "aurora%d: Chip %d id %02x: ",
239                board_No(bp), chip,id);
240         if(sbus_readb(&bp->r[chip]->r[CD180_SRCR]) & 128) {
241                 switch (id) {
242                         case 0x82:printk("CL-CD1864 rev A\n");break;
243                         case 0x83:printk("CL-CD1865 rev A\n");break;
244                         case 0x84:printk("CL-CD1865 rev B\n");break;
245                         case 0x85:printk("CL-CD1865 rev C\n");break;
246                         default:printk("Unknown.\n");
247                 };
248         } else {
249                 switch (id) {
250                         case 0x81:printk("CL-CD180 rev B\n");break;
251                         case 0x82:printk("CL-CD180 rev C\n");break;
252                         default:printk("Unknown.\n");
253                 };
254         }
255         restore_flags(flags);
256 #ifdef AURORA_DEBUG
257         printk("aurora_init_CD180: end\n");
258 #endif
259         return 0;
260 }
261
262 static int valid_irq(unsigned char irq)
263 {
264 int i;
265 for(i=0;i<TYPE_1_IRQS;i++)
266         if (type_1_irq[i]==irq) return 1;
267 return 0;
268 }
269
270 static void aurora_interrupt(int irq, void * dev_id, struct pt_regs * regs);
271
272 /* Main probing routine, also sets irq. */
273 static int aurora_probe(void)
274 {
275         struct sbus_bus *sbus;
276         struct sbus_dev *sdev;
277         int grrr;
278         char buf[30];
279         int bn = 0;
280         struct Aurora_board *bp;
281
282         for_each_sbus(sbus) {
283                 for_each_sbusdev(sdev, sbus) {
284 /*                      printk("Try: %x %s\n",sdev,sdev->prom_name);*/
285                         if (!strcmp(sdev->prom_name, "sio16")) {
286 #ifdef AURORA_DEBUG
287                                 printk(KERN_INFO "aurora: sio16 at %p\n",sdev);
288 #endif
289                                 if((sdev->reg_addrs[0].reg_size!=1) &&
290                                    (sdev->reg_addrs[1].reg_size!=128) &&
291                                    (sdev->reg_addrs[2].reg_size!=128) &&
292                                    (sdev->reg_addrs[3].reg_size!=4)) {
293                                         printk(KERN_ERR "aurora%d: registers' sizes "
294                                                "do not match.\n", bn);
295                                         break;
296                                 }
297                                 bp = &aurora_board[bn];
298                                 bp->r0 = (struct aurora_reg1 *)
299                                         sbus_ioremap(&sdev->resource[0], 0,
300                                                      sdev->reg_addrs[0].reg_size,
301                                                      "sio16");
302                                 if (bp->r0 == NULL) {
303                                         printk(KERN_ERR "aurora%d: can't map "
304                                                "reg_addrs[0]\n", bn);
305                                         break;
306                                 }
307 #ifdef AURORA_DEBUG
308                                 printk("Map reg 0: %p\n", bp->r0);
309 #endif
310                                 bp->r[0] = (struct aurora_reg128 *)
311                                         sbus_ioremap(&sdev->resource[1], 0,
312                                                      sdev->reg_addrs[1].reg_size,
313                                                      "sio16");
314                                 if (bp->r[0] == NULL) {
315                                         printk(KERN_ERR "aurora%d: can't map "
316                                                "reg_addrs[1]\n", bn);
317                                         break;
318                                 }
319 #ifdef AURORA_DEBUG
320                                 printk("Map reg 1: %p\n", bp->r[0]);
321 #endif
322                                 bp->r[1] = (struct aurora_reg128 *)
323                                         sbus_ioremap(&sdev->resource[2], 0,
324                                                      sdev->reg_addrs[2].reg_size,
325                                                      "sio16");
326                                 if (bp->r[1] == NULL) {
327                                         printk(KERN_ERR "aurora%d: can't map "
328                                                "reg_addrs[2]\n", bn);
329                                         break;
330                                 }
331 #ifdef AURORA_DEBUG
332                                 printk("Map reg 2: %p\n", bp->r[1]);
333 #endif
334                                 bp->r3 = (struct aurora_reg4 *)
335                                         sbus_ioremap(&sdev->resource[3], 0,
336                                                      sdev->reg_addrs[3].reg_size,
337                                                      "sio16");
338                                 if (bp->r3 == NULL) {
339                                         printk(KERN_ERR "aurora%d: can't map "
340                                                "reg_addrs[3]\n", bn);
341                                         break;
342                                 }
343 #ifdef AURORA_DEBUG
344                                 printk("Map reg 3: %p\n", bp->r3);
345 #endif
346                                 /* Variables setup */
347                                 bp->flags = 0;
348 #ifdef AURORA_DEBUG
349                                 grrr=prom_getint(sdev->prom_node,"intr");
350                                 printk("intr pri %d\n", grrr);
351 #endif
352                                 if ((bp->irq=irqs[bn]) && valid_irq(bp->irq) &&
353                                     !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
354                                         free_irq(bp->irq|0x30, bp);
355                                 } else
356                                 if ((bp->irq=prom_getint(sdev->prom_node, "bintr")) && valid_irq(bp->irq) &&
357                                     !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
358                                         free_irq(bp->irq|0x30, bp);
359                                 } else
360                                 if ((bp->irq=prom_getint(sdev->prom_node, "intr")) && valid_irq(bp->irq) &&
361                                     !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
362                                         free_irq(bp->irq|0x30, bp);
363                                 } else
364                                 for(grrr=0;grrr<TYPE_1_IRQS;grrr++) {
365                                         if ((bp->irq=type_1_irq[grrr])&&!request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
366                                                 free_irq(bp->irq|0x30, bp);
367                                                 break;
368                                         } else {
369                                         printk(KERN_ERR "aurora%d: Could not get an irq for this board !!!\n",bn);
370                                         bp->flags=0xff;
371                                         }
372                                 }
373                                 if(bp->flags==0xff)break;
374                                 printk(KERN_INFO "aurora%d: irq %d\n",bn,bp->irq&0x0f);
375                                 buf[0]=0;
376                                 grrr=prom_getproperty(sdev->prom_node,"dtr_rts",buf,sizeof(buf));
377                                 if(!strcmp(buf,"swapped")){
378                                         printk(KERN_INFO "aurora%d: Swapped DTR and RTS\n",bn);
379                                         bp->DTR=MSVR_RTS;
380                                         bp->RTS=MSVR_DTR;
381                                         bp->MSVDTR=CD180_MSVRTS;
382                                         bp->MSVRTS=CD180_MSVDTR;
383                                         bp->flags|=AURORA_BOARD_DTR_FLOW_OK;
384                                         }else{
385                                         #ifdef AURORA_FORCE_DTR_FLOW
386                                         printk(KERN_INFO "aurora%d: Forcing swapped DTR-RTS\n",bn);
387                                         bp->DTR=MSVR_RTS;
388                                         bp->RTS=MSVR_DTR;
389                                         bp->MSVDTR=CD180_MSVRTS;
390                                         bp->MSVRTS=CD180_MSVDTR;
391                                         bp->flags|=AURORA_BOARD_DTR_FLOW_OK;
392                                         #else
393                                         printk(KERN_INFO "aurora%d: Normal DTR and RTS\n",bn);
394                                         bp->DTR=MSVR_DTR;
395                                         bp->RTS=MSVR_RTS;
396                                         bp->MSVDTR=CD180_MSVDTR;
397                                         bp->MSVRTS=CD180_MSVRTS;
398                                         #endif
399                                 }
400                                 bp->oscfreq=prom_getint(sdev->prom_node,"clk")*100;
401                                 printk(KERN_INFO "aurora%d: Oscillator: %d Hz\n",bn,bp->oscfreq);
402                                 grrr=prom_getproperty(sdev->prom_node,"chip",buf,sizeof(buf));
403                                 printk(KERN_INFO "aurora%d: Chips: %s\n",bn,buf);
404                                 grrr=prom_getproperty(sdev->prom_node,"manu",buf,sizeof(buf));
405                                 printk(KERN_INFO "aurora%d: Manufacturer: %s\n",bn,buf);
406                                 grrr=prom_getproperty(sdev->prom_node,"model",buf,sizeof(buf));
407                                 printk(KERN_INFO "aurora%d: Model: %s\n",bn,buf);
408                                 grrr=prom_getproperty(sdev->prom_node,"rev",buf,sizeof(buf));
409                                 printk(KERN_INFO "aurora%d: Revision: %s\n",bn,buf);
410                                 grrr=prom_getproperty(sdev->prom_node,"mode",buf,sizeof(buf));
411                                 printk(KERN_INFO "aurora%d: Mode: %s\n",bn,buf);
412                                 #ifdef MODULE
413                                 bp->count=0;
414                                 #endif
415                                 bp->flags = AURORA_BOARD_PRESENT;
416                                 /* hardware ack */
417                                 bp->ACK_MINT=1;
418                                 bp->ACK_TINT=2;
419                                 bp->ACK_RINT=3;
420                                 bn++;
421                         }
422                 }
423         }
424         return bn;
425 }
426
427 static void aurora_release_io_range(struct Aurora_board *bp)
428 {
429         sbus_iounmap((unsigned long)bp->r0, 1);
430         sbus_iounmap((unsigned long)bp->r[0], 128);
431         sbus_iounmap((unsigned long)bp->r[1], 128);
432         sbus_iounmap((unsigned long)bp->r3, 4);
433 }
434
435 static inline void aurora_mark_event(struct Aurora_port * port, int event)
436 {
437 #ifdef AURORA_DEBUG
438         printk("aurora_mark_event: start\n");
439 #endif
440         set_bit(event, &port->event);
441         queue_task(&port->tqueue, &tq_aurora);
442         mark_bh(AURORA_BH);
443 #ifdef AURORA_DEBUG
444         printk("aurora_mark_event: end\n");
445 #endif
446 }
447
448 static __inline__ struct Aurora_port * aurora_get_port(struct Aurora_board const * bp,
449                                                        int chip,
450                                                        unsigned char const *what)
451 {
452         unsigned char channel;
453         struct Aurora_port * port;
454
455         channel = ((chip << 3) |
456                    ((sbus_readb(&bp->r[chip]->r[CD180_GSCR]) & GSCR_CHAN) >> GSCR_CHAN_OFF));
457         port = &aurora_port[board_No(bp) * AURORA_NPORT * AURORA_NCD180 + channel];
458         if (port->flags & ASYNC_INITIALIZED)
459                 return port;
460
461         printk(KERN_DEBUG "aurora%d: %s interrupt from invalid port %d\n",
462                board_No(bp), what, channel);
463         return NULL;
464 }
465
466 static void aurora_receive_exc(struct Aurora_board const * bp, int chip)
467 {
468         struct Aurora_port *port;
469         struct tty_struct *tty;
470         unsigned char status;
471         unsigned char ch;
472         
473         if (!(port = aurora_get_port(bp, chip, "Receive_x")))
474                 return;
475
476         tty = port->tty;
477         if (tty->flip.count >= TTY_FLIPBUF_SIZE)  {
478 #ifdef AURORA_INTNORM
479                 printk("aurora%d: port %d: Working around flip buffer overflow.\n",
480                        board_No(bp), port_No(port));
481 #endif
482                 return;
483         }
484         
485 #ifdef AURORA_REPORT_OVERRUN    
486         status = sbus_readb(&bp->r[chip]->r[CD180_RCSR]);
487         if (status & RCSR_OE)  {
488                 port->overrun++;
489 #if 1
490                 printk("aurora%d: port %d: Overrun. Total %ld overruns.\n",
491                        board_No(bp), port_No(port), port->overrun);
492 #endif          
493         }
494         status &= port->mark_mask;
495 #else   
496         status = sbus_readb(&bp->r[chip]->r[CD180_RCSR]) & port->mark_mask;
497 #endif  
498         ch = sbus_readb(&bp->r[chip]->r[CD180_RDR]);
499         if (!status)
500                 return;
501
502         if (status & RCSR_TOUT)  {
503 /*              printk("aurora%d: port %d: Receiver timeout. Hardware problems ?\n",
504                        board_No(bp), port_No(port));*/
505                 return;
506                 
507         } else if (status & RCSR_BREAK)  {
508                 printk(KERN_DEBUG "aurora%d: port %d: Handling break...\n",
509                        board_No(bp), port_No(port));
510                 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
511                 if (port->flags & ASYNC_SAK)
512                         do_SAK(tty);
513                 
514         } else if (status & RCSR_PE) 
515                 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
516         
517         else if (status & RCSR_FE) 
518                 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
519         
520         else if (status & RCSR_OE)
521                 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
522         
523         else
524                 *tty->flip.flag_buf_ptr++ = 0;
525         
526         *tty->flip.char_buf_ptr++ = ch;
527         tty->flip.count++;
528         queue_task(&tty->flip.tqueue, &tq_timer);
529 }
530
531 static void aurora_receive(struct Aurora_board const * bp, int chip)
532 {
533         struct Aurora_port *port;
534         struct tty_struct *tty;
535         unsigned char count,cnt;
536
537         if (!(port = aurora_get_port(bp, chip, "Receive")))
538                 return;
539         
540         tty = port->tty;
541         
542         count = sbus_readb(&bp->r[chip]->r[CD180_RDCR]);
543
544 #ifdef AURORA_REPORT_FIFO
545         port->hits[count > 8 ? 9 : count]++;
546 #endif
547
548         while (count--)  {
549                 if (tty->flip.count >= TTY_FLIPBUF_SIZE)  {
550 #ifdef AURORA_INTNORM
551                         printk("aurora%d: port %d: Working around flip buffer overflow.\n",
552                                board_No(bp), port_No(port));
553 #endif
554                         break;
555                 }
556                 cnt = sbus_readb(&bp->r[chip]->r[CD180_RDR]);
557                 *tty->flip.char_buf_ptr++ = cnt;
558                 *tty->flip.flag_buf_ptr++ = 0;
559                 tty->flip.count++;
560         }
561         queue_task(&tty->flip.tqueue, &tq_timer);
562 }
563
564 static void aurora_transmit(struct Aurora_board const * bp, int chip)
565 {
566         struct Aurora_port *port;
567         struct tty_struct *tty;
568         unsigned char count;
569         
570         if (!(port = aurora_get_port(bp, chip, "Transmit")))
571                 return;
572                 
573         tty = port->tty;
574         
575         if (port->SRER & SRER_TXEMPTY)  {
576                 /* FIFO drained */
577                 sbus_writeb(port_No(port) & 7,
578                             &bp->r[chip]->r[CD180_CAR]);
579                 udelay(1);
580                 port->SRER &= ~SRER_TXEMPTY;
581                 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
582                 return;
583         }
584         
585         if ((port->xmit_cnt <= 0 && !port->break_length)
586             || tty->stopped || tty->hw_stopped)  {
587                 sbus_writeb(port_No(port) & 7,
588                             &bp->r[chip]->r[CD180_CAR]);
589                 udelay(1);
590                 port->SRER &= ~SRER_TXRDY;
591                 sbus_writeb(port->SRER,
592                             &bp->r[chip]->r[CD180_SRER]);
593                 return;
594         }
595         
596         if (port->break_length)  {
597                 if (port->break_length > 0)  {
598                         if (port->COR2 & COR2_ETC)  {
599                                 sbus_writeb(CD180_C_ESC,
600                                             &bp->r[chip]->r[CD180_TDR]);
601                                 sbus_writeb(CD180_C_SBRK,
602                                             &bp->r[chip]->r[CD180_TDR]);
603                                 port->COR2 &= ~COR2_ETC;
604                         }
605                         count = MIN(port->break_length, 0xff);
606                         sbus_writeb(CD180_C_ESC,
607                                     &bp->r[chip]->r[CD180_TDR]);
608                         sbus_writeb(CD180_C_DELAY,
609                                     &bp->r[chip]->r[CD180_TDR]);
610                         sbus_writeb(count,
611                                     &bp->r[chip]->r[CD180_TDR]);
612                         if (!(port->break_length -= count))
613                                 port->break_length--;
614                 } else  {
615                         sbus_writeb(CD180_C_ESC,
616                                     &bp->r[chip]->r[CD180_TDR]);
617                         sbus_writeb(CD180_C_EBRK,
618                                     &bp->r[chip]->r[CD180_TDR]);
619                         sbus_writeb(port->COR2,
620                                     &bp->r[chip]->r[CD180_COR2]);
621                         aurora_wait_CCR(bp->r[chip]);
622                         sbus_writeb(CCR_CORCHG2,
623                                     &bp->r[chip]->r[CD180_CCR]);
624                         port->break_length = 0;
625                 }
626                 return;
627         }
628         
629         count = CD180_NFIFO;
630         do {
631                 u8 byte = port->xmit_buf[port->xmit_tail++];
632
633                 sbus_writeb(byte, &bp->r[chip]->r[CD180_TDR]);
634                 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
635                 if (--port->xmit_cnt <= 0)
636                         break;
637         } while (--count > 0);
638         
639         if (port->xmit_cnt <= 0)  {
640                 sbus_writeb(port_No(port) & 7,
641                             &bp->r[chip]->r[CD180_CAR]);
642                 udelay(1);
643                 port->SRER &= ~SRER_TXRDY;
644                 sbus_writeb(port->SRER,
645                             &bp->r[chip]->r[CD180_SRER]);
646         }
647         if (port->xmit_cnt <= port->wakeup_chars)
648                 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
649 }
650
651 static void aurora_check_modem(struct Aurora_board const * bp, int chip)
652 {
653         struct Aurora_port *port;
654         struct tty_struct *tty;
655         unsigned char mcr;
656         
657         if (!(port = aurora_get_port(bp, chip, "Modem")))
658                 return;
659                 
660         tty = port->tty;
661         
662         mcr = sbus_readb(&bp->r[chip]->r[CD180_MCR]);
663         if (mcr & MCR_CDCHG)  {
664                 if (sbus_readb(&bp->r[chip]->r[CD180_MSVR]) & MSVR_CD) 
665                         wake_up_interruptible(&port->open_wait);
666                 else if (!((port->flags & ASYNC_CALLOUT_ACTIVE) &&
667                            (port->flags & ASYNC_CALLOUT_NOHUP))) {
668                         MOD_INC_USE_COUNT;
669                         if (schedule_task(&port->tqueue_hangup) == 0)
670                                 MOD_DEC_USE_COUNT;
671                 }
672         }
673         
674 /* We don't have such things yet. My aurora board has DTR and RTS swapped, but that doesn't count in this driver. Let's hope
675  * Aurora didn't made any boards with CTS or DSR broken...
676  */
677 /* #ifdef AURORA_BRAIN_DAMAGED_CTS
678         if (mcr & MCR_CTSCHG)  {
679                 if (aurora_in(bp, CD180_MSVR) & MSVR_CTS)  {
680                         tty->hw_stopped = 0;
681                         port->SRER |= SRER_TXRDY;
682                         if (port->xmit_cnt <= port->wakeup_chars)
683                                 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
684                 } else  {
685                         tty->hw_stopped = 1;
686                         port->SRER &= ~SRER_TXRDY;
687                 }
688                 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
689         }
690         if (mcr & MCR_DSRCHG)  {
691                 if (aurora_in(bp, CD180_MSVR) & MSVR_DSR)  {
692                         tty->hw_stopped = 0;
693                         port->SRER |= SRER_TXRDY;
694                         if (port->xmit_cnt <= port->wakeup_chars)
695                                 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
696                 } else  {
697                         tty->hw_stopped = 1;
698                         port->SRER &= ~SRER_TXRDY;
699                 }
700                 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
701         }
702 #endif AURORA_BRAIN_DAMAGED_CTS */
703         
704         /* Clear change bits */
705         sbus_writeb(0, &bp->r[chip]->r[CD180_MCR]);
706 }
707
708 /* The main interrupt processing routine */
709 static void aurora_interrupt(int irq, void * dev_id, struct pt_regs * regs)
710 {
711         unsigned char status;
712         unsigned char ack,chip/*,chip_id*/;
713         struct Aurora_board * bp = (struct Aurora_board *) dev_id;
714         unsigned long loop = 0;
715
716 #ifdef AURORA_INT_DEBUG
717         printk("IRQ%d %d\n",irq,++irqhit);
718 #ifdef AURORA_FLOODPRO
719         if (irqhit>=AURORA_FLOODPRO)
720                 sbus_writeb(8, &bp->r0->r);
721 #endif
722 #endif
723         
724 /* old  bp = IRQ_to_board[irq&0x0f];*/
725         
726         if (!bp || !(bp->flags & AURORA_BOARD_ACTIVE))
727                 return;
728
729 /*      The while() below takes care of this.
730         status = sbus_readb(&bp->r[0]->r[CD180_SRSR]);
731 #ifdef AURORA_INT_DEBUG
732         printk("mumu: %02x\n", status);
733 #endif
734         if (!(status&SRSR_ANYINT))
735                 return; * Nobody has anything to say, so exit *
736 */
737         while ((loop++ < 48) &&
738                (status = sbus_readb(&bp->r[0]->r[CD180_SRSR]) & SRSR_ANYINT)){
739 #ifdef AURORA_INT_DEBUG
740                 printk("SRSR: %02x\n", status);
741 #endif
742                 if (status & SRSR_REXT) {
743                         ack = sbus_readb(&bp->r3->r[bp->ACK_RINT]);
744 #ifdef AURORA_INT_DEBUG
745                         printk("R-ACK %02x\n", ack);
746 #endif
747                         if ((ack >> 5) == board_No(bp)) {
748                                 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
749                                         if ((ack&GSVR_ITMASK)==GSVR_IT_RGD) {
750                                                 aurora_receive(bp,chip);
751                                                 sbus_writeb(0,
752                                                          &bp->r[chip]->r[CD180_EOSRR]);
753                                         } else if ((ack & GSVR_ITMASK) == GSVR_IT_REXC) {
754                                                 aurora_receive_exc(bp,chip);
755                                                 sbus_writeb(0,
756                                                          &bp->r[chip]->r[CD180_EOSRR]);
757                                         }
758                                 }
759                         }
760                 } else if (status & SRSR_TEXT) {
761                         ack = sbus_readb(&bp->r3->r[bp->ACK_TINT]);
762 #ifdef AURORA_INT_DEBUG
763                         printk("T-ACK %02x\n", ack);
764 #endif
765                         if ((ack >> 5) == board_No(bp)) {
766                                 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
767                                         if ((ack&GSVR_ITMASK)==GSVR_IT_TX) {
768                                                 aurora_transmit(bp,chip);
769                                                 sbus_writeb(0,
770                                                          &bp->r[chip]->r[CD180_EOSRR]);
771                                         }
772                                 }
773                         }
774                 } else if (status & SRSR_MEXT) {
775                         ack = sbus_readb(&bp->r3->r[bp->ACK_MINT]);
776 #ifdef AURORA_INT_DEBUG
777                         printk("M-ACK %02x\n", ack);
778 #endif
779                         if ((ack >> 5) == board_No(bp)) {
780                                 if ((chip = ((ack>>3)&3)-1) < AURORA_NCD180) {
781                                         if ((ack&GSVR_ITMASK)==GSVR_IT_MDM) {
782                                                 aurora_check_modem(bp,chip);
783                                                 sbus_writeb(0,
784                                                          &bp->r[chip]->r[CD180_EOSRR]);
785                                         }
786                                 }
787                         }
788                 }
789         }
790 /* I guess this faster code can be used with CD1865, using AUROPRI and GLOBPRI. */
791 #if 0
792         while ((loop++ < 48)&&(status=bp->r[0]->r[CD180_SRSR]&SRSR_ANYINT)){
793 #ifdef AURORA_INT_DEBUG
794                 printk("SRSR: %02x\n",status);
795 #endif
796                 ack = sbus_readb(&bp->r3->r[0]);
797 #ifdef AURORA_INT_DEBUG
798                 printk("ACK: %02x\n",ack);
799 #endif
800                 if ((ack>>5)==board_No(bp)) {
801                         if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
802                                 ack&=GSVR_ITMASK;
803                                 if (ack==GSVR_IT_RGD) {
804                                         aurora_receive(bp,chip);
805                                         sbus_writeb(0,
806                                                     &bp->r[chip]->r[CD180_EOSRR]);
807                                 } else if (ack==GSVR_IT_REXC) {
808                                         aurora_receive_exc(bp,chip);
809                                         sbus_writeb(0,
810                                                     &bp->r[chip]->r[CD180_EOSRR]);
811                                 } else if (ack==GSVR_IT_TX) {
812                                         aurora_transmit(bp,chip);
813                                         sbus_writeb(0,
814                                                     &bp->r[chip]->r[CD180_EOSRR]);
815                                 } else if (ack==GSVR_IT_MDM) {
816                                         aurora_check_modem(bp,chip);
817                                         sbus_writeb(0,
818                                                     &bp->r[chip]->r[CD180_EOSRR]);
819                                 }
820                         }
821                 }
822         }
823 #endif
824
825 /* This is the old handling routine, used in riscom8 for only one CD180. I keep it here for reference. */
826 #if 0
827         for(chip=0;chip<AURORA_NCD180;chip++){
828                 chip_id=(board_No(bp)<<5)|((chip+1)<<3);
829                 loop=0;
830                 while ((loop++ < 1) &&
831                        ((status = sbus_readb(&bp->r[chip]->r[CD180_SRSR])) &
832                         (SRSR_TEXT | SRSR_MEXT | SRSR_REXT))) {
833
834                         if (status & SRSR_REXT) {
835                                 ack = sbus_readb(&bp->r3->r[bp->ACK_RINT]);
836                                 if (ack == (chip_id | GSVR_IT_RGD)) {
837 #ifdef AURORA_INTMSG
838                                         printk("RX ACK\n");
839 #endif
840                                         aurora_receive(bp,chip);
841                                 } else if (ack == (chip_id | GSVR_IT_REXC)) {
842 #ifdef AURORA_INTMSG
843                                         printk("RXC ACK\n");
844 #endif
845                                         aurora_receive_exc(bp,chip);
846                                 } else {
847 #ifdef AURORA_INTNORM
848                                         printk("aurora%d-%d: Bad receive ack 0x%02x.\n",
849                                                board_No(bp), chip, ack);
850 #endif
851                                 }
852                         } else if (status & SRSR_TEXT) {
853                                 ack = sbus_readb(&bp->r3->r[bp->ACK_TINT]);
854                                 if (ack == (chip_id | GSVR_IT_TX)){
855 #ifdef AURORA_INTMSG
856                                         printk("TX ACK\n");
857 #endif
858                                         aurora_transmit(bp,chip);
859                                 } else {
860 #ifdef AURORA_INTNORM
861                                         printk("aurora%d-%d: Bad transmit ack 0x%02x.\n",
862                                                board_No(bp), chip, ack);
863 #endif
864                                 }
865                         } else  if (status & SRSR_MEXT)  {
866                                 ack = sbus_readb(&bp->r3->r[bp->ACK_MINT]);
867                                 if (ack == (chip_id | GSVR_IT_MDM)){
868 #ifdef AURORA_INTMSG
869                                         printk("MDM ACK\n");
870 #endif
871                                         aurora_check_modem(bp,chip);
872                                 } else {
873 #ifdef AURORA_INTNORM
874                                         printk("aurora%d-%d: Bad modem ack 0x%02x.\n",
875                                                board_No(bp), chip, ack);
876 #endif
877                                 }
878                         }
879                         sbus_writeb(0, &bp->r[chip]->r[CD180_EOSRR]);
880                 }
881         }
882 #endif
883 }
884
885 #ifdef AURORA_INT_DEBUG
886 static void aurora_timer (unsigned long ignored);
887
888 static struct timer_list
889 aurora_poll_timer = { NULL, NULL, 0, 0, aurora_timer };
890
891 static void
892 aurora_timer (unsigned long ignored)
893 {
894         unsigned long flags;
895         int i;
896
897         save_flags(flags); cli();
898
899         printk("SRSR: %02x,%02x - ",
900                sbus_readb(&aurora_board[0].r[0]->r[CD180_SRSR]),
901                sbus_readb(&aurora_board[0].r[1]->r[CD180_SRSR]));
902         for (i = 0; i < 4; i++) {
903                 udelay(1);
904                 printk("%02x ",
905                        sbus_readb(&aurora_board[0].r3->r[i]));
906         }
907         printk("\n");
908
909         aurora_poll_timer.expires = jiffies + 300;
910         add_timer (&aurora_poll_timer);
911
912         restore_flags(flags);
913 }
914 #endif
915
916 /*
917  *  Routines for open & close processing.
918  */
919
920 /* Called with disabled interrupts */
921 static int aurora_setup_board(struct Aurora_board * bp)
922 {
923         int error;
924         
925 #ifdef AURORA_ALLIRQ
926         int i;
927         for (i = 0; i < AURORA_ALLIRQ; i++) {
928                 error = request_irq(allirq[i]|0x30, aurora_interrupt, SA_SHIRQ,
929                                     "sio16", bp);
930                 if (error)
931                         printk(KERN_ERR "IRQ%d request error %d\n",
932                                allirq[i], error);
933         }
934 #else
935         error = request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ,
936                             "sio16", bp);
937         if (error) {
938                 printk(KERN_ERR "IRQ request error %d\n", error);
939                 return error;
940         }
941 #endif
942         /* Board reset */
943         sbus_writeb(0, &bp->r0->r);
944         udelay(1);
945         if (bp->flags & AURORA_BOARD_TYPE_2) {
946                 /* unknown yet */
947         } else {
948                 sbus_writeb((AURORA_CFG_ENABLE_IO | AURORA_CFG_ENABLE_IRQ |
949                              (((bp->irq)&0x0f)>>2)),
950                             &bp->r0->r);
951         }
952         udelay(10000);
953
954         if (aurora_init_CD180(bp,0))error=1;error=0;
955         if (aurora_init_CD180(bp,1))error++;
956         if (error == AURORA_NCD180) {
957                 printk(KERN_ERR "Both chips failed initialisation.\n");
958                 return -EIO;
959         }
960
961 #ifdef AURORA_INT_DEBUG
962         aurora_poll_timer.expires= jiffies + 1;
963         add_timer(&aurora_poll_timer);
964 #endif
965 #ifdef AURORA_DEBUG
966         printk("aurora_setup_board: end\n");
967 #endif
968         return 0;
969 }
970
971 /* Called with disabled interrupts */
972 static void aurora_shutdown_board(struct Aurora_board *bp)
973 {
974         int i;
975
976 #ifdef AURORA_DEBUG
977         printk("aurora_shutdown_board: start\n");
978 #endif
979
980 #ifdef AURORA_INT_DEBUG
981         del_timer(&aurora_poll_timer);
982 #endif
983
984 #ifdef AURORA_ALLIRQ
985         for(i=0;i<AURORA_ALLIRQ;i++){
986                 free_irq(allirq[i]|0x30, bp);
987 /*              IRQ_to_board[allirq[i]&0xf] = NULL;*/
988         }
989 #else
990         free_irq(bp->irq|0x30, bp);
991 /*      IRQ_to_board[bp->irq&0xf] = NULL;*/
992 #endif  
993         /* Drop all DTR's */
994         for(i=0;i<16;i++){
995                 sbus_writeb(i & 7, &bp->r[i>>3]->r[CD180_CAR]);
996                 udelay(1);
997                 sbus_writeb(0, &bp->r[i>>3]->r[CD180_MSVR]);
998                 udelay(1);
999         }
1000         /* Board shutdown */
1001         sbus_writeb(0, &bp->r0->r);
1002
1003 #ifdef AURORA_DEBUG
1004         printk("aurora_shutdown_board: end\n");
1005 #endif
1006 }
1007
1008 /* Setting up port characteristics. 
1009  * Must be called with disabled interrupts
1010  */
1011 static void aurora_change_speed(struct Aurora_board *bp, struct Aurora_port *port)
1012 {
1013         struct tty_struct *tty;
1014         unsigned long baud;
1015         long tmp;
1016         unsigned char cor1 = 0, cor3 = 0;
1017         unsigned char mcor1 = 0, mcor2 = 0,chip;
1018         
1019 #ifdef AURORA_DEBUG
1020         printk("aurora_change_speed: start\n");
1021 #endif
1022         if (!(tty = port->tty) || !tty->termios)
1023                 return;
1024                 
1025         chip = AURORA_CD180(port_No(port));
1026
1027         port->SRER  = 0;
1028         port->COR2 = 0;
1029         port->MSVR = MSVR_RTS|MSVR_DTR;
1030         
1031         baud = tty_get_baud_rate(tty);
1032         
1033         /* Select port on the board */
1034         sbus_writeb(port_No(port) & 7,
1035                     &bp->r[chip]->r[CD180_CAR]);
1036         udelay(1);
1037         
1038         if (!baud)  {
1039                 /* Drop DTR & exit */
1040                 port->MSVR &= ~(bp->DTR|bp->RTS);
1041                 sbus_writeb(port->MSVR,
1042                             &bp->r[chip]->r[CD180_MSVR]);
1043                 return;
1044         } else  {
1045                 /* Set DTR on */
1046                 port->MSVR |= bp->DTR;
1047                 sbus_writeb(port->MSVR,
1048                             &bp->r[chip]->r[CD180_MSVR]);
1049         }
1050         
1051         /* Now we must calculate some speed dependant things. */
1052         
1053         /* Set baud rate for port. */
1054         tmp = (((bp->oscfreq + baud/2) / baud +
1055                 CD180_TPC/2) / CD180_TPC);
1056
1057 /*      tmp = (bp->oscfreq/7)/baud;
1058         if((tmp%10)>4)tmp=tmp/10+1;else tmp=tmp/10;*/
1059 /*      printk("Prescaler period: %d\n",tmp);*/
1060
1061         sbus_writeb((tmp >> 8) & 0xff,
1062                     &bp->r[chip]->r[CD180_RBPRH]);
1063         sbus_writeb((tmp >> 8) & 0xff,
1064                     &bp->r[chip]->r[CD180_TBPRH]);
1065         sbus_writeb(tmp & 0xff, &bp->r[chip]->r[CD180_RBPRL]);
1066         sbus_writeb(tmp & 0xff, &bp->r[chip]->r[CD180_TBPRL]);
1067         
1068         baud = (baud + 5) / 10;   /* Estimated CPS */
1069         
1070         /* Two timer ticks seems enough to wakeup something like SLIP driver */
1071         tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;           
1072         port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
1073                                               SERIAL_XMIT_SIZE - 1 : tmp);
1074         
1075         /* Receiver timeout will be transmission time for 1.5 chars */
1076         tmp = (AURORA_TPS + AURORA_TPS/2 + baud/2) / baud;
1077         tmp = (tmp > 0xff) ? 0xff : tmp;
1078         sbus_writeb(tmp, &bp->r[chip]->r[CD180_RTPR]);
1079         
1080         switch (C_CSIZE(tty))  {
1081          case CS5:
1082                 cor1 |= COR1_5BITS;
1083                 break;
1084          case CS6:
1085                 cor1 |= COR1_6BITS;
1086                 break;
1087          case CS7:
1088                 cor1 |= COR1_7BITS;
1089                 break;
1090          case CS8:
1091                 cor1 |= COR1_8BITS;
1092                 break;
1093         }
1094         
1095         if (C_CSTOPB(tty)) 
1096                 cor1 |= COR1_2SB;
1097         
1098         cor1 |= COR1_IGNORE;
1099         if (C_PARENB(tty))  {
1100                 cor1 |= COR1_NORMPAR;
1101                 if (C_PARODD(tty)) 
1102                         cor1 |= COR1_ODDP;
1103                 if (I_INPCK(tty)) 
1104                         cor1 &= ~COR1_IGNORE;
1105         }
1106         /* Set marking of some errors */
1107         port->mark_mask = RCSR_OE | RCSR_TOUT;
1108         if (I_INPCK(tty)) 
1109                 port->mark_mask |= RCSR_FE | RCSR_PE;
1110         if (I_BRKINT(tty) || I_PARMRK(tty)) 
1111                 port->mark_mask |= RCSR_BREAK;
1112         if (I_IGNPAR(tty)) 
1113                 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
1114         if (I_IGNBRK(tty))  {
1115                 port->mark_mask &= ~RCSR_BREAK;
1116                 if (I_IGNPAR(tty)) 
1117                         /* Real raw mode. Ignore all */
1118                         port->mark_mask &= ~RCSR_OE;
1119         }
1120         /* Enable Hardware Flow Control */
1121         if (C_CRTSCTS(tty))  {
1122 /*#ifdef AURORA_BRAIN_DAMAGED_CTS
1123                 port->SRER |= SRER_DSR | SRER_CTS;
1124                 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
1125                 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
1126                 tty->hw_stopped = !(aurora_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
1127 #else*/
1128                 port->COR2 |= COR2_CTSAE;
1129 /*#endif*/
1130                 if (bp->flags&AURORA_BOARD_DTR_FLOW_OK) {
1131                         mcor1 |= AURORA_RXTH;
1132                 }
1133         }
1134         /* Enable Software Flow Control. FIXME: I'm not sure about this */
1135         /* Some people reported that it works, but I still doubt */
1136         if (I_IXON(tty))  {
1137                 port->COR2 |= COR2_TXIBE;
1138                 cor3 |= (COR3_FCT | COR3_SCDE);
1139                 if (I_IXANY(tty))
1140                         port->COR2 |= COR2_IXM;
1141                 sbus_writeb(START_CHAR(tty),
1142                             &bp->r[chip]->r[CD180_SCHR1]);
1143                 sbus_writeb(STOP_CHAR(tty),
1144                             &bp->r[chip]->r[CD180_SCHR2]);
1145                 sbus_writeb(START_CHAR(tty),
1146                             &bp->r[chip]->r[CD180_SCHR3]);
1147                 sbus_writeb(STOP_CHAR(tty),
1148                             &bp->r[chip]->r[CD180_SCHR4]);
1149         }
1150         if (!C_CLOCAL(tty))  {
1151                 /* Enable CD check */
1152                 port->SRER |= SRER_CD;
1153                 mcor1 |= MCOR1_CDZD;
1154                 mcor2 |= MCOR2_CDOD;
1155         }
1156         
1157         if (C_CREAD(tty)) 
1158                 /* Enable receiver */
1159                 port->SRER |= SRER_RXD;
1160         
1161         /* Set input FIFO size (1-8 bytes) */
1162         cor3 |= AURORA_RXFIFO; 
1163         /* Setting up CD180 channel registers */
1164         sbus_writeb(cor1, &bp->r[chip]->r[CD180_COR1]);
1165         sbus_writeb(port->COR2, &bp->r[chip]->r[CD180_COR2]);
1166         sbus_writeb(cor3, &bp->r[chip]->r[CD180_COR3]);
1167         /* Make CD180 know about registers change */
1168         aurora_wait_CCR(bp->r[chip]);
1169         sbus_writeb(CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3,
1170                     &bp->r[chip]->r[CD180_CCR]);
1171         /* Setting up modem option registers */
1172         sbus_writeb(mcor1, &bp->r[chip]->r[CD180_MCOR1]);
1173         sbus_writeb(mcor2, &bp->r[chip]->r[CD180_MCOR2]);
1174         /* Enable CD180 transmitter & receiver */
1175         aurora_wait_CCR(bp->r[chip]);
1176         sbus_writeb(CCR_TXEN | CCR_RXEN, &bp->r[chip]->r[CD180_CCR]);
1177         /* Enable interrupts */
1178         sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1179         /* And finally set RTS on */
1180         sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
1181 #ifdef AURORA_DEBUG
1182         printk("aurora_change_speed: end\n");
1183 #endif
1184 }
1185
1186 /* Must be called with interrupts enabled */
1187 static int aurora_setup_port(struct Aurora_board *bp, struct Aurora_port *port)
1188 {
1189         unsigned long flags;
1190         
1191 #ifdef AURORA_DEBUG
1192         printk("aurora_setup_port: start %d\n",port_No(port));
1193 #endif
1194         if (port->flags & ASYNC_INITIALIZED)
1195                 return 0;
1196                 
1197         if (!port->xmit_buf) {
1198                 /* We may sleep in get_free_page() */
1199                 unsigned long tmp;
1200                 
1201                 if (!(tmp = get_free_page(GFP_KERNEL)))
1202                         return -ENOMEM;
1203                     
1204                 if (port->xmit_buf) {
1205                         free_page(tmp);
1206                         return -ERESTARTSYS;
1207                 }
1208                 port->xmit_buf = (unsigned char *) tmp;
1209         }
1210                 
1211         save_flags(flags); cli();
1212                 
1213         if (port->tty) 
1214                 clear_bit(TTY_IO_ERROR, &port->tty->flags);
1215                 
1216 #ifdef MODULE
1217         if (port->count == 1) {
1218                 MOD_INC_USE_COUNT;
1219                 if((++bp->count) == 1)
1220                         bp->flags |= AURORA_BOARD_ACTIVE;
1221         }
1222 #endif
1223
1224         port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1225         aurora_change_speed(bp, port);
1226         port->flags |= ASYNC_INITIALIZED;
1227                 
1228         restore_flags(flags);
1229 #ifdef AURORA_DEBUG
1230         printk("aurora_setup_port: end\n");
1231 #endif
1232         return 0;
1233 }
1234
1235 /* Must be called with interrupts disabled */
1236 static void aurora_shutdown_port(struct Aurora_board *bp, struct Aurora_port *port)
1237 {
1238         struct tty_struct *tty;
1239         unsigned char chip;
1240
1241 #ifdef AURORA_DEBUG
1242         printk("aurora_shutdown_port: start\n");
1243 #endif
1244         if (!(port->flags & ASYNC_INITIALIZED)) 
1245                 return;
1246         
1247         chip = AURORA_CD180(port_No(port));
1248         
1249 #ifdef AURORA_REPORT_OVERRUN
1250         printk("aurora%d: port %d: Total %ld overruns were detected.\n",
1251                board_No(bp), port_No(port), port->overrun);
1252 #endif  
1253 #ifdef AURORA_REPORT_FIFO
1254         {
1255                 int i;
1256                 
1257                 printk("aurora%d: port %d: FIFO hits [ ",
1258                        board_No(bp), port_No(port));
1259                 for (i = 0; i < 10; i++)  {
1260                         printk("%ld ", port->hits[i]);
1261                 }
1262                 printk("].\n");
1263         }
1264 #endif  
1265         if (port->xmit_buf)  {
1266                 free_page((unsigned long) port->xmit_buf);
1267                 port->xmit_buf = NULL;
1268         }
1269
1270         if (!(tty = port->tty) || C_HUPCL(tty))  {
1271                 /* Drop DTR */
1272                 port->MSVR &= ~(bp->DTR|bp->RTS);
1273                 sbus_writeb(port->MSVR,
1274                             &bp->r[chip]->r[CD180_MSVR]);
1275         }
1276         
1277         /* Select port */
1278         sbus_writeb(port_No(port) & 7,
1279                     &bp->r[chip]->r[CD180_CAR]);
1280         udelay(1);
1281
1282         /* Reset port */
1283         aurora_wait_CCR(bp->r[chip]);
1284         sbus_writeb(CCR_SOFTRESET, &bp->r[chip]->r[CD180_CCR]);
1285
1286         /* Disable all interrupts from this port */
1287         port->SRER = 0;
1288         sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1289         
1290         if (tty)  
1291                 set_bit(TTY_IO_ERROR, &tty->flags);
1292         port->flags &= ~ASYNC_INITIALIZED;
1293
1294 #ifdef MODULE
1295         if (--bp->count < 0)  {
1296                 printk(KERN_DEBUG "aurora%d: aurora_shutdown_port: "
1297                        "bad board count: %d\n",
1298                        board_No(bp), bp->count);
1299                 bp->count = 0;
1300         }
1301         
1302         MOD_DEC_USE_COUNT;
1303         if (!bp->count)
1304                 bp->flags &= ~AURORA_BOARD_ACTIVE;
1305 #endif
1306
1307 #ifdef AURORA_DEBUG
1308         printk("aurora_shutdown_port: end\n");
1309 #endif
1310 }
1311
1312         
1313 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1314                            struct Aurora_port *port)
1315 {
1316         DECLARE_WAITQUEUE(wait, current);
1317         struct Aurora_board *bp = port_Board(port);
1318         int    retval;
1319         int    do_clocal = 0;
1320         int    CD;
1321         unsigned char chip;
1322         
1323 #ifdef AURORA_DEBUG
1324         printk("block_til_ready: start\n");
1325 #endif
1326         chip = AURORA_CD180(port_No(port));
1327
1328         /* If the device is in the middle of being closed, then block
1329          * until it's done, and then try again.
1330          */
1331         if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
1332                 interruptible_sleep_on(&port->close_wait);
1333                 if (port->flags & ASYNC_HUP_NOTIFY)
1334                         return -EAGAIN;
1335                 else
1336                         return -ERESTARTSYS;
1337         }
1338
1339         /* If non-blocking mode is set, or the port is not enabled,
1340          * then make the check up front and then exit.
1341          */
1342         if ((filp->f_flags & O_NONBLOCK) ||
1343             (tty->flags & (1 << TTY_IO_ERROR))) {
1344                 if (port->flags & ASYNC_CALLOUT_ACTIVE)
1345                         return -EBUSY;
1346                 port->flags |= ASYNC_NORMAL_ACTIVE;
1347                 return 0;
1348         }
1349
1350         if (port->flags & ASYNC_CALLOUT_ACTIVE) {
1351                 if (port->normal_termios.c_cflag & CLOCAL) 
1352                         do_clocal = 1;
1353         } else {
1354                 if (C_CLOCAL(tty))  
1355                         do_clocal = 1;
1356         }
1357
1358         /* Block waiting for the carrier detect and the line to become
1359          * free (i.e., not in use by the callout).  While we are in
1360          * this loop, info->count is dropped by one, so that
1361          * rs_close() knows when to free things.  We restore it upon
1362          * exit, either normal or abnormal.
1363          */
1364         retval = 0;
1365         add_wait_queue(&port->open_wait, &wait);
1366         cli();
1367         if (!tty_hung_up_p(filp))
1368                 port->count--;
1369         sti();
1370         port->blocked_open++;
1371         while (1) {
1372                 cli();
1373                 sbus_writeb(port_No(port) & 7,
1374                             &bp->r[chip]->r[CD180_CAR]);
1375                 udelay(1);
1376                 CD = sbus_readb(&bp->r[chip]->r[CD180_MSVR]) & MSVR_CD;
1377                 if (!(port->flags & ASYNC_CALLOUT_ACTIVE))  {
1378                         port->MSVR=bp->RTS;
1379
1380                         /* auto drops DTR */
1381                         sbus_writeb(port->MSVR,
1382                                     &bp->r[chip]->r[CD180_MSVR]);
1383                 }
1384                 sti();
1385                 set_current_state(TASK_INTERRUPTIBLE);
1386                 if (tty_hung_up_p(filp) ||
1387                     !(port->flags & ASYNC_INITIALIZED)) {
1388                         if (port->flags & ASYNC_HUP_NOTIFY)
1389                                 retval = -EAGAIN;
1390                         else
1391                                 retval = -ERESTARTSYS;  
1392                         break;
1393                 }
1394                 if (/*!(port->flags & ASYNC_CALLOUT_ACTIVE) &&*/
1395                     !(port->flags & ASYNC_CLOSING) &&
1396                     (do_clocal || CD))
1397                         break;
1398                 if (signal_pending(current)) {
1399                         retval = -ERESTARTSYS;
1400                         break;
1401                 }
1402                 schedule();
1403         }
1404         current->state = TASK_RUNNING;
1405         remove_wait_queue(&port->open_wait, &wait);
1406         if (!tty_hung_up_p(filp))
1407                 port->count++;
1408         port->blocked_open--;
1409         if (retval)
1410                 return retval;
1411         
1412         port->flags |= ASYNC_NORMAL_ACTIVE;
1413 #ifdef AURORA_DEBUG
1414         printk("block_til_ready: end\n");
1415 #endif
1416         return 0;
1417 }       
1418
1419 static int aurora_open(struct tty_struct * tty, struct file * filp)
1420 {
1421         int board;
1422         int error;
1423         struct Aurora_port * port;
1424         struct Aurora_board * bp;
1425         unsigned long flags;
1426         
1427 #ifdef AURORA_DEBUG
1428         printk("aurora_open: start\n");
1429 #endif
1430         
1431         board = AURORA_BOARD(MINOR(tty->device));
1432         if (board > AURORA_NBOARD ||
1433             !(aurora_board[board].flags & AURORA_BOARD_PRESENT)) {
1434 #ifdef AURORA_DEBUG
1435                 printk("aurora_open: error board %d present %d\n",
1436                        board, aurora_board[board].flags & AURORA_BOARD_PRESENT);
1437 #endif
1438                 return -ENODEV;
1439         }
1440         
1441         bp = &aurora_board[board];
1442         port = aurora_port + board * AURORA_NPORT * AURORA_NCD180 + AURORA_PORT(MINOR(tty->device));
1443         if (aurora_paranoia_check(port, tty->device, "aurora_open")) {
1444 #ifdef AURORA_DEBUG
1445                 printk("aurora_open: error paranoia check\n");
1446 #endif
1447                 return -ENODEV;
1448         }
1449         
1450         port->count++;
1451         tty->driver_data = port;
1452         port->tty = tty;
1453         
1454         if ((error = aurora_setup_port(bp, port))) {
1455 #ifdef AURORA_DEBUG
1456                 printk("aurora_open: error aurora_setup_port ret %d\n",error);
1457 #endif
1458                 return error;
1459         }
1460
1461         if ((error = block_til_ready(tty, filp, port))) {
1462 #ifdef AURORA_DEBUG
1463                 printk("aurora_open: error block_til_ready ret %d\n",error);
1464 #endif
1465                 return error;
1466         }
1467         
1468         if ((port->count == 1) && (port->flags & ASYNC_SPLIT_TERMIOS)) {
1469                 *tty->termios = port->normal_termios;
1470                 save_flags(flags); cli();
1471                 aurora_change_speed(bp, port);
1472                 restore_flags(flags);
1473         }
1474
1475         port->session = current->session;
1476         port->pgrp = current->pgrp;
1477 #ifdef AURORA_DEBUG
1478         printk("aurora_open: end\n");
1479 #endif
1480         return 0;
1481 }
1482
1483 static void aurora_close(struct tty_struct * tty, struct file * filp)
1484 {
1485         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1486         struct Aurora_board *bp;
1487         unsigned long flags;
1488         unsigned long timeout;
1489         unsigned char chip;
1490         
1491 #ifdef AURORA_DEBUG
1492         printk("aurora_close: start\n");
1493 #endif
1494         
1495         if (!port || aurora_paranoia_check(port, tty->device, "close"))
1496                 return;
1497         
1498         chip = AURORA_CD180(port_No(port));
1499
1500         save_flags(flags); cli();
1501         if (tty_hung_up_p(filp))  {
1502                 restore_flags(flags);
1503                 return;
1504         }
1505         
1506         bp = port_Board(port);
1507         if ((tty->count == 1) && (port->count != 1))  {
1508                 printk(KERN_DEBUG "aurora%d: aurora_close: bad port count; "
1509                        "tty->count is 1, port count is %d\n",
1510                        board_No(bp), port->count);
1511                 port->count = 1;
1512         }
1513         if (--port->count < 0)  {
1514                 printk(KERN_DEBUG "aurora%d: aurora_close: bad port "
1515                        "count for tty%d: %d\n",
1516                        board_No(bp), port_No(port), port->count);
1517                 port->count = 0;
1518         }
1519         if (port->count)  {
1520                 restore_flags(flags);
1521                 return;
1522         }
1523         port->flags |= ASYNC_CLOSING;
1524
1525         /* Save the termios structure, since this port may have
1526          * separate termios for callout and dialin.
1527          */
1528         if (port->flags & ASYNC_NORMAL_ACTIVE)
1529                 port->normal_termios = *tty->termios;
1530 /*      if (port->flags & ASYNC_CALLOUT_ACTIVE)
1531                 port->callout_termios = *tty->termios;*/
1532
1533         /* Now we wait for the transmit buffer to clear; and we notify 
1534          * the line discipline to only process XON/XOFF characters.
1535          */
1536         tty->closing = 1;
1537         if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE){
1538 #ifdef AURORA_DEBUG
1539                 printk("aurora_close: waiting to flush...\n");
1540 #endif
1541                 tty_wait_until_sent(tty, port->closing_wait);
1542         }
1543
1544         /* At this point we stop accepting input.  To do this, we
1545          * disable the receive line status interrupts, and tell the
1546          * interrupt driver to stop checking the data ready bit in the
1547          * line status register.
1548          */
1549         port->SRER &= ~SRER_RXD;
1550         if (port->flags & ASYNC_INITIALIZED) {
1551                 port->SRER &= ~SRER_TXRDY;
1552                 port->SRER |= SRER_TXEMPTY;
1553                 sbus_writeb(port_No(port) & 7,
1554                             &bp->r[chip]->r[CD180_CAR]);
1555                 udelay(1);
1556                 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1557                 /*
1558                  * Before we drop DTR, make sure the UART transmitter
1559                  * has completely drained; this is especially
1560                  * important if there is a transmit FIFO!
1561                  */
1562                 timeout = jiffies+HZ;
1563                 while(port->SRER & SRER_TXEMPTY)  {
1564                         current->state = TASK_INTERRUPTIBLE;
1565                         schedule_timeout(port->timeout);
1566                         if (time_after(jiffies, timeout))
1567                                 break;
1568                 }
1569         }
1570 #ifdef AURORA_DEBUG
1571         printk("aurora_close: shutdown_port\n");
1572 #endif
1573         aurora_shutdown_port(bp, port);
1574         if (tty->driver.flush_buffer)
1575                 tty->driver.flush_buffer(tty);
1576         tty_ldisc_flush(tty);
1577         tty->closing = 0;
1578         port->event = 0;
1579         port->tty = 0;
1580         if (port->blocked_open) {
1581                 if (port->close_delay) {
1582                         current->state = TASK_INTERRUPTIBLE;
1583                         schedule_timeout(port->close_delay);
1584                 }
1585                 wake_up_interruptible(&port->open_wait);
1586         }
1587         port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
1588                          ASYNC_CLOSING);
1589         wake_up_interruptible(&port->close_wait);
1590         restore_flags(flags);
1591 #ifdef AURORA_DEBUG
1592         printk("aurora_close: end\n");
1593 #endif
1594 }
1595
1596 static int aurora_write(struct tty_struct * tty, int from_user, 
1597                         const unsigned char *buf, int count)
1598 {
1599         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1600         struct Aurora_board *bp;
1601         int c, total = 0;
1602         unsigned long flags;
1603         unsigned char chip;
1604
1605 #ifdef AURORA_DEBUG
1606         printk("aurora_write: start %d\n",count);
1607 #endif
1608         if (aurora_paranoia_check(port, tty->device, "aurora_write"))
1609                 return 0;
1610                 
1611         chip = AURORA_CD180(port_No(port));
1612         
1613         bp = port_Board(port);
1614
1615         if (!tty || !port->xmit_buf || !tmp_buf)
1616                 return 0;
1617
1618         save_flags(flags);
1619         if (from_user) {
1620                 down(&tmp_buf_sem);
1621                 while (1) {
1622                         c = MIN(count, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1623                                            SERIAL_XMIT_SIZE - port->xmit_head));
1624                         if (c <= 0)
1625                                 break;
1626
1627                         c -= copy_from_user(tmp_buf, buf, c);
1628                         if (!c) {
1629                                 if (!total)
1630                                         total = -EFAULT;
1631                                 break;
1632                         }
1633                         cli();
1634                         c = MIN(c, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1635                                        SERIAL_XMIT_SIZE - port->xmit_head));
1636                         memcpy(port->xmit_buf + port->xmit_head, tmp_buf, c);
1637                         port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1638                         port->xmit_cnt += c;
1639                         restore_flags(flags);
1640
1641                         buf += c;
1642                         count -= c;
1643                         total += c;
1644                 }
1645                 up(&tmp_buf_sem);
1646         } else {
1647                 while (1) {
1648                         cli();
1649                         c = MIN(count, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1650                                            SERIAL_XMIT_SIZE - port->xmit_head));
1651                         if (c <= 0) {
1652                                 restore_flags(flags);
1653                                 break;
1654                         }
1655                         memcpy(port->xmit_buf + port->xmit_head, buf, c);
1656                         port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1657                         port->xmit_cnt += c;
1658                         restore_flags(flags);
1659
1660                         buf += c;
1661                         count -= c;
1662                         total += c;
1663                 }
1664         }
1665
1666         cli();
1667         if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1668             !(port->SRER & SRER_TXRDY)) {
1669                 port->SRER |= SRER_TXRDY;
1670                 sbus_writeb(port_No(port) & 7,
1671                             &bp->r[chip]->r[CD180_CAR]);
1672                 udelay(1);
1673                 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1674         }
1675         restore_flags(flags);
1676 #ifdef AURORA_DEBUG
1677         printk("aurora_write: end %d\n",total);
1678 #endif
1679         return total;
1680 }
1681
1682 static void aurora_put_char(struct tty_struct * tty, unsigned char ch)
1683 {
1684         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1685         unsigned long flags;
1686
1687 #ifdef AURORA_DEBUG
1688         printk("aurora_put_char: start %c\n",ch);
1689 #endif
1690         if (aurora_paranoia_check(port, tty->device, "aurora_put_char"))
1691                 return;
1692
1693         if (!tty || !port->xmit_buf)
1694                 return;
1695
1696         save_flags(flags); cli();
1697         
1698         if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
1699                 restore_flags(flags);
1700                 return;
1701         }
1702
1703         port->xmit_buf[port->xmit_head++] = ch;
1704         port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1705         port->xmit_cnt++;
1706         restore_flags(flags);
1707 #ifdef AURORA_DEBUG
1708         printk("aurora_put_char: end\n");
1709 #endif
1710 }
1711
1712 static void aurora_flush_chars(struct tty_struct * tty)
1713 {
1714         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1715         unsigned long flags;
1716         unsigned char chip;
1717
1718 /*#ifdef AURORA_DEBUG
1719         printk("aurora_flush_chars: start\n");
1720 #endif*/
1721         if (aurora_paranoia_check(port, tty->device, "aurora_flush_chars"))
1722                 return;
1723                 
1724         chip = AURORA_CD180(port_No(port));
1725         
1726         if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1727             !port->xmit_buf)
1728                 return;
1729
1730         save_flags(flags); cli();
1731         port->SRER |= SRER_TXRDY;
1732         sbus_writeb(port_No(port) & 7,
1733                     &port_Board(port)->r[chip]->r[CD180_CAR]);
1734         udelay(1);
1735         sbus_writeb(port->SRER,
1736                     &port_Board(port)->r[chip]->r[CD180_SRER]);
1737         restore_flags(flags);
1738 /*#ifdef AURORA_DEBUG
1739         printk("aurora_flush_chars: end\n");
1740 #endif*/
1741 }
1742
1743 static int aurora_write_room(struct tty_struct * tty)
1744 {
1745         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1746         int     ret;
1747
1748 #ifdef AURORA_DEBUG
1749         printk("aurora_write_room: start\n");
1750 #endif
1751         if (aurora_paranoia_check(port, tty->device, "aurora_write_room"))
1752                 return 0;
1753
1754         ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1755         if (ret < 0)
1756                 ret = 0;
1757 #ifdef AURORA_DEBUG
1758         printk("aurora_write_room: end\n");
1759 #endif
1760         return ret;
1761 }
1762
1763 static int aurora_chars_in_buffer(struct tty_struct *tty)
1764 {
1765         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1766                                 
1767         if (aurora_paranoia_check(port, tty->device, "aurora_chars_in_buffer"))
1768                 return 0;
1769         
1770         return port->xmit_cnt;
1771 }
1772
1773 static void aurora_flush_buffer(struct tty_struct *tty)
1774 {
1775         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1776         unsigned long flags;
1777
1778 #ifdef AURORA_DEBUG
1779         printk("aurora_flush_buffer: start\n");
1780 #endif
1781         if (aurora_paranoia_check(port, tty->device, "aurora_flush_buffer"))
1782                 return;
1783
1784         save_flags(flags); cli();
1785         port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1786         restore_flags(flags);
1787
1788         tty_wakeup(tty);        
1789 #ifdef AURORA_DEBUG
1790         printk("aurora_flush_buffer: end\n");
1791 #endif
1792 }
1793
1794 static int aurora_get_modem_info(struct Aurora_port * port, unsigned int *value)
1795 {
1796         struct Aurora_board * bp;
1797         unsigned char status,chip;
1798         unsigned int result;
1799         unsigned long flags;
1800
1801 #ifdef AURORA_DEBUG
1802         printk("aurora_get_modem_info: start\n");
1803 #endif
1804         chip = AURORA_CD180(port_No(port));
1805
1806         bp = port_Board(port);
1807
1808         save_flags(flags); cli();
1809
1810         sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1811         udelay(1);
1812
1813         status = sbus_readb(&bp->r[chip]->r[CD180_MSVR]);
1814         result = 0/*bp->r[chip]->r[AURORA_RI] & (1u << port_No(port)) ? 0 : TIOCM_RNG*/;
1815
1816         restore_flags(flags);
1817
1818         result |= ((status & bp->RTS) ? TIOCM_RTS : 0)
1819                 | ((status & bp->DTR) ? TIOCM_DTR : 0)
1820                 | ((status & MSVR_CD)  ? TIOCM_CAR : 0)
1821                 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1822                 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1823
1824         put_user(result,(unsigned long *) value);
1825 #ifdef AURORA_DEBUG
1826         printk("aurora_get_modem_info: end\n");
1827 #endif
1828         return 0;
1829 }
1830
1831 static int aurora_set_modem_info(struct Aurora_port * port, unsigned int cmd,
1832                                  unsigned int *value)
1833 {
1834         unsigned int arg;
1835         unsigned long flags;
1836         struct Aurora_board *bp = port_Board(port);
1837         unsigned char chip;
1838
1839 #ifdef AURORA_DEBUG
1840         printk("aurora_set_modem_info: start\n");
1841 #endif
1842         if (get_user(arg, value))
1843                 return -EFAULT;
1844         chip = AURORA_CD180(port_No(port));
1845         switch (cmd) {
1846          case TIOCMBIS: 
1847                 if (arg & TIOCM_RTS) 
1848                         port->MSVR |= bp->RTS;
1849                 if (arg & TIOCM_DTR)
1850                         port->MSVR |= bp->DTR;
1851                 break;
1852         case TIOCMBIC:
1853                 if (arg & TIOCM_RTS)
1854                         port->MSVR &= ~bp->RTS;
1855                 if (arg & TIOCM_DTR)
1856                         port->MSVR &= ~bp->DTR;
1857                 break;
1858         case TIOCMSET:
1859                 port->MSVR = (arg & TIOCM_RTS) ? (port->MSVR | bp->RTS) : 
1860                                                  (port->MSVR & ~bp->RTS);
1861                 port->MSVR = (arg & TIOCM_DTR) ? (port->MSVR | bp->RTS) :
1862                                                  (port->MSVR & ~bp->RTS);
1863                 break;
1864          default:
1865                 return -EINVAL;
1866         };
1867
1868         save_flags(flags); cli();
1869
1870         sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1871         udelay(1);
1872
1873         sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
1874
1875         restore_flags(flags);
1876 #ifdef AURORA_DEBUG
1877         printk("aurora_set_modem_info: end\n");
1878 #endif
1879         return 0;
1880 }
1881
1882 static void aurora_send_break(struct Aurora_port * port, unsigned long length)
1883 {
1884         struct Aurora_board *bp = port_Board(port);
1885         unsigned long flags;
1886         unsigned char chip;
1887         
1888 #ifdef AURORA_DEBUG
1889         printk("aurora_send_break: start\n");
1890 #endif
1891         chip = AURORA_CD180(port_No(port));
1892         
1893         save_flags(flags); cli();
1894
1895         port->break_length = AURORA_TPS / HZ * length;
1896         port->COR2 |= COR2_ETC;
1897         port->SRER  |= SRER_TXRDY;
1898         sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1899         udelay(1);
1900
1901         sbus_writeb(port->COR2, &bp->r[chip]->r[CD180_COR2]);
1902         sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1903         aurora_wait_CCR(bp->r[chip]);
1904
1905         sbus_writeb(CCR_CORCHG2, &bp->r[chip]->r[CD180_CCR]);
1906         aurora_wait_CCR(bp->r[chip]);
1907
1908         restore_flags(flags);
1909 #ifdef AURORA_DEBUG
1910         printk("aurora_send_break: end\n");
1911 #endif
1912 }
1913
1914 static int aurora_set_serial_info(struct Aurora_port * port,
1915                                   struct serial_struct * newinfo)
1916 {
1917         struct serial_struct tmp;
1918         struct Aurora_board *bp = port_Board(port);
1919         int change_speed;
1920         unsigned long flags;
1921
1922 #ifdef AURORA_DEBUG
1923         printk("aurora_set_serial_info: start\n");
1924 #endif
1925         if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1926                 return -EFAULT;
1927 #if 0   
1928         if ((tmp.irq != bp->irq) ||
1929             (tmp.port != bp->base) ||
1930             (tmp.type != PORT_CIRRUS) ||
1931             (tmp.baud_base != (bp->oscfreq + CD180_TPC/2) / CD180_TPC) ||
1932             (tmp.custom_divisor != 0) ||
1933             (tmp.xmit_fifo_size != CD180_NFIFO) ||
1934             (tmp.flags & ~AURORA_LEGAL_FLAGS))
1935                 return -EINVAL;
1936 #endif  
1937         
1938         change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1939                         (tmp.flags & ASYNC_SPD_MASK));
1940         
1941         if (!capable(CAP_SYS_ADMIN)) {
1942                 if ((tmp.close_delay != port->close_delay) ||
1943                     (tmp.closing_wait != port->closing_wait) ||
1944                     ((tmp.flags & ~ASYNC_USR_MASK) !=
1945                      (port->flags & ~ASYNC_USR_MASK)))  
1946                         return -EPERM;
1947                 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1948                                (tmp.flags & ASYNC_USR_MASK));
1949         } else  {
1950                 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1951                                (tmp.flags & ASYNC_FLAGS));
1952                 port->close_delay = tmp.close_delay;
1953                 port->closing_wait = tmp.closing_wait;
1954         }
1955         if (change_speed)  {
1956                 save_flags(flags); cli();
1957                 aurora_change_speed(bp, port);
1958                 restore_flags(flags);
1959         }
1960 #ifdef AURORA_DEBUG
1961         printk("aurora_set_serial_info: end\n");
1962 #endif
1963         return 0;
1964 }
1965
1966 extern int aurora_get_serial_info(struct Aurora_port * port,
1967                                   struct serial_struct * retinfo)
1968 {
1969         struct serial_struct tmp;
1970         struct Aurora_board *bp = port_Board(port);
1971         int error;
1972         
1973 #ifdef AURORA_DEBUG
1974         printk("aurora_get_serial_info: start\n");
1975 #endif
1976         error = verify_area(VERIFY_WRITE, (void *) retinfo, sizeof(tmp));
1977         if (error)
1978                 return error;
1979         
1980         memset(&tmp, 0, sizeof(tmp));
1981         tmp.type = PORT_CIRRUS;
1982         tmp.line = port - aurora_port;
1983         tmp.port = 0;
1984         tmp.irq  = bp->irq;
1985         tmp.flags = port->flags;
1986         tmp.baud_base = (bp->oscfreq + CD180_TPC/2) / CD180_TPC;
1987         tmp.close_delay = port->close_delay * HZ/100;
1988         tmp.closing_wait = port->closing_wait * HZ/100;
1989         tmp.xmit_fifo_size = CD180_NFIFO;
1990         copy_to_user(retinfo, &tmp, sizeof(tmp));
1991 #ifdef AURORA_DEBUG
1992 printk("aurora_get_serial_info: end\n");
1993 #endif
1994         return 0;
1995 }
1996
1997 static int aurora_ioctl(struct tty_struct * tty, struct file * filp, 
1998                     unsigned int cmd, unsigned long arg)
1999                     
2000 {
2001         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2002         int retval;
2003
2004 #ifdef AURORA_DEBUG
2005         printk("aurora_ioctl: start\n");
2006 #endif
2007         if (aurora_paranoia_check(port, tty->device, "aurora_ioctl"))
2008                 return -ENODEV;
2009         
2010         switch (cmd) {
2011         case TCSBRK:    /* SVID version: non-zero arg --> no break */
2012                 retval = tty_check_change(tty);
2013                 if (retval)
2014                         return retval;
2015                 tty_wait_until_sent(tty, 0);
2016                 if (!arg)
2017                         aurora_send_break(port, HZ/4);  /* 1/4 second */
2018                 return 0;
2019         case TCSBRKP:   /* support for POSIX tcsendbreak() */
2020                 retval = tty_check_change(tty);
2021                 if (retval)
2022                         return retval;
2023                 tty_wait_until_sent(tty, 0);
2024                 aurora_send_break(port, arg ? arg*(HZ/10) : HZ/4);
2025                 return 0;
2026         case TIOCGSOFTCAR:
2027                 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *)arg);
2028         case TIOCSSOFTCAR:
2029                 if (get_user(arg,(unsigned long *)arg))
2030                         return -EFAULT;
2031                 tty->termios->c_cflag =
2032                         ((tty->termios->c_cflag & ~CLOCAL) |
2033                          (arg ? CLOCAL : 0));
2034                 return 0;
2035         case TIOCMGET:
2036                 retval = verify_area(VERIFY_WRITE, (void *) arg,
2037                                     sizeof(unsigned int));
2038                 if (retval)
2039                         return retval;
2040                 return aurora_get_modem_info(port, (unsigned int *) arg);
2041         case TIOCMBIS:
2042         case TIOCMBIC:
2043         case TIOCMSET:
2044                 return aurora_set_modem_info(port, cmd, (unsigned int *) arg);
2045         case TIOCGSERIAL:       
2046                 return aurora_get_serial_info(port, (struct serial_struct *) arg);
2047         case TIOCSSERIAL:       
2048                 return aurora_set_serial_info(port, (struct serial_struct *) arg);
2049         default:
2050                 return -ENOIOCTLCMD;
2051         };
2052 #ifdef AURORA_DEBUG
2053         printk("aurora_ioctl: end\n");
2054 #endif
2055         return 0;
2056 }
2057
2058 static void aurora_throttle(struct tty_struct * tty)
2059 {
2060         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2061         struct Aurora_board *bp;
2062         unsigned long flags;
2063         unsigned char chip;
2064
2065 #ifdef AURORA_DEBUG
2066         printk("aurora_throttle: start\n");
2067 #endif
2068         if (aurora_paranoia_check(port, tty->device, "aurora_throttle"))
2069                 return;
2070         
2071         bp = port_Board(port);
2072         chip = AURORA_CD180(port_No(port));
2073         
2074         save_flags(flags); cli();
2075         port->MSVR &= ~bp->RTS;
2076         sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
2077         udelay(1);
2078         if (I_IXOFF(tty))  {
2079                 aurora_wait_CCR(bp->r[chip]);
2080                 sbus_writeb(CCR_SSCH2, &bp->r[chip]->r[CD180_CCR]);
2081                 aurora_wait_CCR(bp->r[chip]);
2082         }
2083         sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
2084         restore_flags(flags);
2085 #ifdef AURORA_DEBUG
2086         printk("aurora_throttle: end\n");
2087 #endif
2088 }
2089
2090 static void aurora_unthrottle(struct tty_struct * tty)
2091 {
2092         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2093         struct Aurora_board *bp;
2094         unsigned long flags;
2095         unsigned char chip;
2096
2097 #ifdef AURORA_DEBUG
2098         printk("aurora_unthrottle: start\n");
2099 #endif
2100         if (aurora_paranoia_check(port, tty->device, "aurora_unthrottle"))
2101                 return;
2102         
2103         bp = port_Board(port);
2104         
2105         chip = AURORA_CD180(port_No(port));
2106         
2107         save_flags(flags); cli();
2108         port->MSVR |= bp->RTS;
2109         sbus_writeb(port_No(port) & 7,
2110                     &bp->r[chip]->r[CD180_CAR]);
2111         udelay(1);
2112         if (I_IXOFF(tty))  {
2113                 aurora_wait_CCR(bp->r[chip]);
2114                 sbus_writeb(CCR_SSCH1,
2115                             &bp->r[chip]->r[CD180_CCR]);
2116                 aurora_wait_CCR(bp->r[chip]);
2117         }
2118         sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
2119         restore_flags(flags);
2120 #ifdef AURORA_DEBUG
2121         printk("aurora_unthrottle: end\n");
2122 #endif
2123 }
2124
2125 static void aurora_stop(struct tty_struct * tty)
2126 {
2127         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2128         struct Aurora_board *bp;
2129         unsigned long flags;
2130         unsigned char chip;
2131
2132 #ifdef AURORA_DEBUG
2133         printk("aurora_stop: start\n");
2134 #endif
2135         if (aurora_paranoia_check(port, tty->device, "aurora_stop"))
2136                 return;
2137         
2138         bp = port_Board(port);
2139         
2140         chip = AURORA_CD180(port_No(port));
2141         
2142         save_flags(flags); cli();
2143         port->SRER &= ~SRER_TXRDY;
2144         sbus_writeb(port_No(port) & 7,
2145                     &bp->r[chip]->r[CD180_CAR]);
2146         udelay(1);
2147         sbus_writeb(port->SRER,
2148                     &bp->r[chip]->r[CD180_SRER]);
2149         restore_flags(flags);
2150 #ifdef AURORA_DEBUG
2151         printk("aurora_stop: end\n");
2152 #endif
2153 }
2154
2155 static void aurora_start(struct tty_struct * tty)
2156 {
2157         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2158         struct Aurora_board *bp;
2159         unsigned long flags;
2160         unsigned char chip;
2161
2162 #ifdef AURORA_DEBUG
2163         printk("aurora_start: start\n");
2164 #endif
2165         if (aurora_paranoia_check(port, tty->device, "aurora_start"))
2166                 return;
2167         
2168         bp = port_Board(port);
2169         
2170         chip = AURORA_CD180(port_No(port));
2171         
2172         save_flags(flags); cli();
2173         if (port->xmit_cnt && port->xmit_buf && !(port->SRER & SRER_TXRDY))  {
2174                 port->SRER |= SRER_TXRDY;
2175                 sbus_writeb(port_No(port) & 7,
2176                             &bp->r[chip]->r[CD180_CAR]);
2177                 udelay(1);
2178                 sbus_writeb(port->SRER,
2179                             &bp->r[chip]->r[CD180_SRER]);
2180         }
2181         restore_flags(flags);
2182 #ifdef AURORA_DEBUG
2183         printk("aurora_start: end\n");
2184 #endif
2185 }
2186
2187 /*
2188  * This routine is called from the scheduler tqueue when the interrupt
2189  * routine has signalled that a hangup has occurred.  The path of
2190  * hangup processing is:
2191  *
2192  *      serial interrupt routine -> (scheduler tqueue) ->
2193  *      do_aurora_hangup() -> tty->hangup() -> aurora_hangup()
2194  * 
2195  */
2196 static void do_aurora_hangup(void *private_)
2197 {
2198         struct Aurora_port      *port = (struct Aurora_port *) private_;
2199         struct tty_struct       *tty;
2200
2201 #ifdef AURORA_DEBUG
2202         printk("do_aurora_hangup: start\n");
2203 #endif
2204         tty = port->tty;
2205         if (tty != NULL) {
2206                 tty_hangup(tty);        /* FIXME: module removal race - AKPM */
2207 #ifdef AURORA_DEBUG
2208                 printk("do_aurora_hangup: end\n");
2209 #endif
2210         }
2211         MOD_DEC_USE_COUNT;
2212 }
2213
2214 static void aurora_hangup(struct tty_struct * tty)
2215 {
2216         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2217         struct Aurora_board *bp;
2218                                 
2219 #ifdef AURORA_DEBUG
2220         printk("aurora_hangup: start\n");
2221 #endif
2222         if (aurora_paranoia_check(port, tty->device, "aurora_hangup"))
2223                 return;
2224         
2225         bp = port_Board(port);
2226         
2227         aurora_shutdown_port(bp, port);
2228         port->event = 0;
2229         port->count = 0;
2230         port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
2231         port->tty = 0;
2232         wake_up_interruptible(&port->open_wait);
2233 #ifdef AURORA_DEBUG
2234         printk("aurora_hangup: end\n");
2235 #endif
2236 }
2237
2238 static void aurora_set_termios(struct tty_struct * tty, struct termios * old_termios)
2239 {
2240         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2241         unsigned long flags;
2242
2243 #ifdef AURORA_DEBUG
2244         printk("aurora_set_termios: start\n");
2245 #endif
2246         if (aurora_paranoia_check(port, tty->device, "aurora_set_termios"))
2247                 return;
2248         
2249         if (tty->termios->c_cflag == old_termios->c_cflag &&
2250             tty->termios->c_iflag == old_termios->c_iflag)
2251                 return;
2252
2253         save_flags(flags); cli();
2254         aurora_change_speed(port_Board(port), port);
2255         restore_flags(flags);
2256
2257         if ((old_termios->c_cflag & CRTSCTS) &&
2258             !(tty->termios->c_cflag & CRTSCTS)) {
2259                 tty->hw_stopped = 0;
2260                 aurora_start(tty);
2261         }
2262 #ifdef AURORA_DEBUG
2263         printk("aurora_set_termios: end\n");
2264 #endif
2265 }
2266
2267 static void do_aurora_bh(void)
2268 {
2269          run_task_queue(&tq_aurora);
2270 }
2271
2272 static void do_softint(void *private_)
2273 {
2274         struct Aurora_port      *port = (struct Aurora_port *) private_;
2275         struct tty_struct       *tty;
2276
2277 #ifdef AURORA_DEBUG
2278         printk("do_softint: start\n");
2279 #endif
2280         tty = port->tty;
2281         if (tty == NULL)
2282                 return;
2283
2284         if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
2285                 tty_wakeup(tty);
2286         }
2287 #ifdef AURORA_DEBUG
2288         printk("do_softint: end\n");
2289 #endif
2290 }
2291
2292 static int aurora_init_drivers(void)
2293 {
2294         int error;
2295         int i;
2296
2297 #ifdef AURORA_DEBUG
2298         printk("aurora_init_drivers: start\n");
2299 #endif
2300         tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL);
2301         if (tmp_buf == NULL) {
2302                 printk(KERN_ERR "aurora: Couldn't get free page.\n");
2303                 return 1;
2304         }
2305         init_bh(AURORA_BH, do_aurora_bh);
2306 /*      memset(IRQ_to_board, 0, sizeof(IRQ_to_board));*/
2307         memset(&aurora_driver, 0, sizeof(aurora_driver));
2308         aurora_driver.magic = TTY_DRIVER_MAGIC;
2309         aurora_driver.name = "ttyA";
2310         aurora_driver.major = AURORA_MAJOR;
2311         aurora_driver.num = AURORA_TNPORTS;
2312         aurora_driver.type = TTY_DRIVER_TYPE_SERIAL;
2313         aurora_driver.subtype = AURORA_TYPE_NORMAL;
2314         aurora_driver.init_termios = tty_std_termios;
2315         aurora_driver.init_termios.c_cflag =
2316                 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2317         aurora_driver.flags = TTY_DRIVER_REAL_RAW;
2318         aurora_driver.refcount = &aurora_refcount;
2319         aurora_driver.table = aurora_table;
2320         aurora_driver.termios = aurora_termios;
2321         aurora_driver.termios_locked = aurora_termios_locked;
2322
2323         aurora_driver.open  = aurora_open;
2324         aurora_driver.close = aurora_close;
2325         aurora_driver.write = aurora_write;
2326         aurora_driver.put_char = aurora_put_char;
2327         aurora_driver.flush_chars = aurora_flush_chars;
2328         aurora_driver.write_room = aurora_write_room;
2329         aurora_driver.chars_in_buffer = aurora_chars_in_buffer;
2330         aurora_driver.flush_buffer = aurora_flush_buffer;
2331         aurora_driver.ioctl = aurora_ioctl;
2332         aurora_driver.throttle = aurora_throttle;
2333         aurora_driver.unthrottle = aurora_unthrottle;
2334         aurora_driver.set_termios = aurora_set_termios;
2335         aurora_driver.stop = aurora_stop;
2336         aurora_driver.start = aurora_start;
2337         aurora_driver.hangup = aurora_hangup;
2338
2339         error = tty_register_driver(&aurora_driver);
2340         if (error) {
2341                 free_page((unsigned long) tmp_buf);
2342                 printk(KERN_ERR "aurora: Couldn't register aurora driver, error = %d\n",
2343                        error);
2344                 return 1;
2345         }
2346         
2347         memset(aurora_port, 0, sizeof(aurora_port));
2348         for (i = 0; i < AURORA_TNPORTS; i++)  {
2349                 aurora_port[i].normal_termios  = aurora_driver.init_termios;
2350                 aurora_port[i].magic = AURORA_MAGIC;
2351                 aurora_port[i].tqueue.routine = do_softint;
2352                 aurora_port[i].tqueue.data = &aurora_port[i];
2353                 aurora_port[i].tqueue_hangup.routine = do_aurora_hangup;
2354                 aurora_port[i].tqueue_hangup.data = &aurora_port[i];
2355                 aurora_port[i].close_delay = 50 * HZ/100;
2356                 aurora_port[i].closing_wait = 3000 * HZ/100;
2357                 init_waitqueue_head(&aurora_port[i].open_wait);
2358                 init_waitqueue_head(&aurora_port[i].close_wait);
2359         }
2360 #ifdef AURORA_DEBUG
2361         printk("aurora_init_drivers: end\n");
2362 #endif
2363         return 0;
2364 }
2365
2366 static void aurora_release_drivers(void)
2367 {
2368 #ifdef AURORA_DEBUG
2369         printk("aurora_release_drivers: start\n");
2370 #endif
2371         free_page((unsigned long)tmp_buf);
2372         tty_unregister_driver(&aurora_driver);
2373 #ifdef AURORA_DEBUG
2374         printk("aurora_release_drivers: end\n");
2375 #endif
2376 }
2377
2378 /*
2379  * Called at boot time.
2380  *
2381  * You can specify IO base for up to RC_NBOARD cards,
2382  * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
2383  * Note that there will be no probing at default
2384  * addresses in this case.
2385  *
2386  */
2387 void __init aurora_setup(char *str, int *ints)
2388 {
2389         int i;
2390
2391         for(i=0;(i<ints[0])&&(i<4);i++) {
2392                 if (ints[i+1]) irqs[i]=ints[i+1];
2393                 }
2394 }
2395
2396 static int __init aurora_real_init(void)
2397 {
2398         int found;
2399         int i;
2400
2401         printk(KERN_INFO "aurora: Driver starting.\n");
2402         if(aurora_init_drivers())
2403                 return -EIO;
2404         found = aurora_probe();
2405         if(!found) {
2406                 aurora_release_drivers();
2407                 printk(KERN_INFO "aurora: No Aurora Multiport boards detected.\n");
2408                 return -EIO;
2409         } else {
2410                 printk(KERN_INFO "aurora: %d boards found.\n", found);
2411         }
2412         for (i = 0; i < found; i++) {
2413                 int ret = aurora_setup_board(&aurora_board[i]);
2414
2415                 if (ret) {
2416 #ifdef AURORA_DEBUG
2417                         printk(KERN_ERR "aurora_init: error aurora_setup_board ret %d\n",
2418                                ret);
2419 #endif
2420                         return ret;
2421                 }
2422         }
2423         return 0;
2424 }
2425
2426 int irq  = 0;
2427 int irq1 = 0;
2428 int irq2 = 0;
2429 int irq3 = 0;
2430 MODULE_PARM(irq , "i");
2431 MODULE_PARM(irq1, "i");
2432 MODULE_PARM(irq2, "i");
2433 MODULE_PARM(irq3, "i");
2434
2435 static int __init aurora_init(void) 
2436 {
2437         if (irq ) irqs[0]=irq ;
2438         if (irq1) irqs[1]=irq1;
2439         if (irq2) irqs[2]=irq2;
2440         if (irq3) irqs[3]=irq3;
2441         return aurora_real_init();
2442 }
2443         
2444 static void __exit aurora_cleanup(void)
2445 {
2446         int i;
2447         
2448 #ifdef AURORA_DEBUG
2449 printk("cleanup_module: aurora_release_drivers\n");
2450 #endif
2451
2452         aurora_release_drivers();
2453         for (i = 0; i < AURORA_NBOARD; i++)
2454                 if (aurora_board[i].flags & AURORA_BOARD_PRESENT) {
2455                         aurora_shutdown_board(&aurora_board[i]);
2456                         aurora_release_io_range(&aurora_board[i]);
2457                 }
2458 }
2459
2460 module_init(aurora_init);
2461 module_exit(aurora_cleanup);
2462 MODULE_LICENSE("GPL");