import of ftp.dlink.com/GPL/DSMG-600_reB/ppclinux.tar.gz
[linux-2.4.21-pre4.git] / drivers / sbus / char / aurora.c
1 /*      $Id: aurora.c,v 1.1.1.1 2005/04/11 02:50:34 jack 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         if (tty->ldisc.flush_buffer)
1577                 tty->ldisc.flush_buffer(tty);
1578         tty->closing = 0;
1579         port->event = 0;
1580         port->tty = 0;
1581         if (port->blocked_open) {
1582                 if (port->close_delay) {
1583                         current->state = TASK_INTERRUPTIBLE;
1584                         schedule_timeout(port->close_delay);
1585                 }
1586                 wake_up_interruptible(&port->open_wait);
1587         }
1588         port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
1589                          ASYNC_CLOSING);
1590         wake_up_interruptible(&port->close_wait);
1591         restore_flags(flags);
1592 #ifdef AURORA_DEBUG
1593         printk("aurora_close: end\n");
1594 #endif
1595 }
1596
1597 static int aurora_write(struct tty_struct * tty, int from_user, 
1598                         const unsigned char *buf, int count)
1599 {
1600         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1601         struct Aurora_board *bp;
1602         int c, total = 0;
1603         unsigned long flags;
1604         unsigned char chip;
1605
1606 #ifdef AURORA_DEBUG
1607         printk("aurora_write: start %d\n",count);
1608 #endif
1609         if (aurora_paranoia_check(port, tty->device, "aurora_write"))
1610                 return 0;
1611                 
1612         chip = AURORA_CD180(port_No(port));
1613         
1614         bp = port_Board(port);
1615
1616         if (!tty || !port->xmit_buf || !tmp_buf)
1617                 return 0;
1618
1619         save_flags(flags);
1620         if (from_user) {
1621                 down(&tmp_buf_sem);
1622                 while (1) {
1623                         c = MIN(count, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1624                                            SERIAL_XMIT_SIZE - port->xmit_head));
1625                         if (c <= 0)
1626                                 break;
1627
1628                         c -= copy_from_user(tmp_buf, buf, c);
1629                         if (!c) {
1630                                 if (!total)
1631                                         total = -EFAULT;
1632                                 break;
1633                         }
1634                         cli();
1635                         c = MIN(c, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1636                                        SERIAL_XMIT_SIZE - port->xmit_head));
1637                         memcpy(port->xmit_buf + port->xmit_head, tmp_buf, c);
1638                         port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1639                         port->xmit_cnt += c;
1640                         restore_flags(flags);
1641
1642                         buf += c;
1643                         count -= c;
1644                         total += c;
1645                 }
1646                 up(&tmp_buf_sem);
1647         } else {
1648                 while (1) {
1649                         cli();
1650                         c = MIN(count, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1651                                            SERIAL_XMIT_SIZE - port->xmit_head));
1652                         if (c <= 0) {
1653                                 restore_flags(flags);
1654                                 break;
1655                         }
1656                         memcpy(port->xmit_buf + port->xmit_head, buf, c);
1657                         port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1658                         port->xmit_cnt += c;
1659                         restore_flags(flags);
1660
1661                         buf += c;
1662                         count -= c;
1663                         total += c;
1664                 }
1665         }
1666
1667         cli();
1668         if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1669             !(port->SRER & SRER_TXRDY)) {
1670                 port->SRER |= SRER_TXRDY;
1671                 sbus_writeb(port_No(port) & 7,
1672                             &bp->r[chip]->r[CD180_CAR]);
1673                 udelay(1);
1674                 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1675         }
1676         restore_flags(flags);
1677 #ifdef AURORA_DEBUG
1678         printk("aurora_write: end %d\n",total);
1679 #endif
1680         return total;
1681 }
1682
1683 static void aurora_put_char(struct tty_struct * tty, unsigned char ch)
1684 {
1685         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1686         unsigned long flags;
1687
1688 #ifdef AURORA_DEBUG
1689         printk("aurora_put_char: start %c\n",ch);
1690 #endif
1691         if (aurora_paranoia_check(port, tty->device, "aurora_put_char"))
1692                 return;
1693
1694         if (!tty || !port->xmit_buf)
1695                 return;
1696
1697         save_flags(flags); cli();
1698         
1699         if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
1700                 restore_flags(flags);
1701                 return;
1702         }
1703
1704         port->xmit_buf[port->xmit_head++] = ch;
1705         port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1706         port->xmit_cnt++;
1707         restore_flags(flags);
1708 #ifdef AURORA_DEBUG
1709         printk("aurora_put_char: end\n");
1710 #endif
1711 }
1712
1713 static void aurora_flush_chars(struct tty_struct * tty)
1714 {
1715         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1716         unsigned long flags;
1717         unsigned char chip;
1718
1719 /*#ifdef AURORA_DEBUG
1720         printk("aurora_flush_chars: start\n");
1721 #endif*/
1722         if (aurora_paranoia_check(port, tty->device, "aurora_flush_chars"))
1723                 return;
1724                 
1725         chip = AURORA_CD180(port_No(port));
1726         
1727         if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1728             !port->xmit_buf)
1729                 return;
1730
1731         save_flags(flags); cli();
1732         port->SRER |= SRER_TXRDY;
1733         sbus_writeb(port_No(port) & 7,
1734                     &port_Board(port)->r[chip]->r[CD180_CAR]);
1735         udelay(1);
1736         sbus_writeb(port->SRER,
1737                     &port_Board(port)->r[chip]->r[CD180_SRER]);
1738         restore_flags(flags);
1739 /*#ifdef AURORA_DEBUG
1740         printk("aurora_flush_chars: end\n");
1741 #endif*/
1742 }
1743
1744 static int aurora_write_room(struct tty_struct * tty)
1745 {
1746         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1747         int     ret;
1748
1749 #ifdef AURORA_DEBUG
1750         printk("aurora_write_room: start\n");
1751 #endif
1752         if (aurora_paranoia_check(port, tty->device, "aurora_write_room"))
1753                 return 0;
1754
1755         ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1756         if (ret < 0)
1757                 ret = 0;
1758 #ifdef AURORA_DEBUG
1759         printk("aurora_write_room: end\n");
1760 #endif
1761         return ret;
1762 }
1763
1764 static int aurora_chars_in_buffer(struct tty_struct *tty)
1765 {
1766         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1767                                 
1768         if (aurora_paranoia_check(port, tty->device, "aurora_chars_in_buffer"))
1769                 return 0;
1770         
1771         return port->xmit_cnt;
1772 }
1773
1774 static void aurora_flush_buffer(struct tty_struct *tty)
1775 {
1776         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1777         unsigned long flags;
1778
1779 #ifdef AURORA_DEBUG
1780         printk("aurora_flush_buffer: start\n");
1781 #endif
1782         if (aurora_paranoia_check(port, tty->device, "aurora_flush_buffer"))
1783                 return;
1784
1785         save_flags(flags); cli();
1786         port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1787         restore_flags(flags);
1788         
1789         wake_up_interruptible(&tty->write_wait);
1790         if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1791             tty->ldisc.write_wakeup)
1792                 (tty->ldisc.write_wakeup)(tty);
1793 #ifdef AURORA_DEBUG
1794         printk("aurora_flush_buffer: end\n");
1795 #endif
1796 }
1797
1798 static int aurora_get_modem_info(struct Aurora_port * port, unsigned int *value)
1799 {
1800         struct Aurora_board * bp;
1801         unsigned char status,chip;
1802         unsigned int result;
1803         unsigned long flags;
1804
1805 #ifdef AURORA_DEBUG
1806         printk("aurora_get_modem_info: start\n");
1807 #endif
1808         chip = AURORA_CD180(port_No(port));
1809
1810         bp = port_Board(port);
1811
1812         save_flags(flags); cli();
1813
1814         sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1815         udelay(1);
1816
1817         status = sbus_readb(&bp->r[chip]->r[CD180_MSVR]);
1818         result = 0/*bp->r[chip]->r[AURORA_RI] & (1u << port_No(port)) ? 0 : TIOCM_RNG*/;
1819
1820         restore_flags(flags);
1821
1822         result |= ((status & bp->RTS) ? TIOCM_RTS : 0)
1823                 | ((status & bp->DTR) ? TIOCM_DTR : 0)
1824                 | ((status & MSVR_CD)  ? TIOCM_CAR : 0)
1825                 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1826                 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1827
1828         put_user(result,(unsigned long *) value);
1829 #ifdef AURORA_DEBUG
1830         printk("aurora_get_modem_info: end\n");
1831 #endif
1832         return 0;
1833 }
1834
1835 static int aurora_set_modem_info(struct Aurora_port * port, unsigned int cmd,
1836                                  unsigned int *value)
1837 {
1838         unsigned int arg;
1839         unsigned long flags;
1840         struct Aurora_board *bp = port_Board(port);
1841         unsigned char chip;
1842
1843 #ifdef AURORA_DEBUG
1844         printk("aurora_set_modem_info: start\n");
1845 #endif
1846         if (get_user(arg, value))
1847                 return -EFAULT;
1848         chip = AURORA_CD180(port_No(port));
1849         switch (cmd) {
1850          case TIOCMBIS: 
1851                 if (arg & TIOCM_RTS) 
1852                         port->MSVR |= bp->RTS;
1853                 if (arg & TIOCM_DTR)
1854                         port->MSVR |= bp->DTR;
1855                 break;
1856         case TIOCMBIC:
1857                 if (arg & TIOCM_RTS)
1858                         port->MSVR &= ~bp->RTS;
1859                 if (arg & TIOCM_DTR)
1860                         port->MSVR &= ~bp->DTR;
1861                 break;
1862         case TIOCMSET:
1863                 port->MSVR = (arg & TIOCM_RTS) ? (port->MSVR | bp->RTS) : 
1864                                                  (port->MSVR & ~bp->RTS);
1865                 port->MSVR = (arg & TIOCM_DTR) ? (port->MSVR | bp->RTS) :
1866                                                  (port->MSVR & ~bp->RTS);
1867                 break;
1868          default:
1869                 return -EINVAL;
1870         };
1871
1872         save_flags(flags); cli();
1873
1874         sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1875         udelay(1);
1876
1877         sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
1878
1879         restore_flags(flags);
1880 #ifdef AURORA_DEBUG
1881         printk("aurora_set_modem_info: end\n");
1882 #endif
1883         return 0;
1884 }
1885
1886 static void aurora_send_break(struct Aurora_port * port, unsigned long length)
1887 {
1888         struct Aurora_board *bp = port_Board(port);
1889         unsigned long flags;
1890         unsigned char chip;
1891         
1892 #ifdef AURORA_DEBUG
1893         printk("aurora_send_break: start\n");
1894 #endif
1895         chip = AURORA_CD180(port_No(port));
1896         
1897         save_flags(flags); cli();
1898
1899         port->break_length = AURORA_TPS / HZ * length;
1900         port->COR2 |= COR2_ETC;
1901         port->SRER  |= SRER_TXRDY;
1902         sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1903         udelay(1);
1904
1905         sbus_writeb(port->COR2, &bp->r[chip]->r[CD180_COR2]);
1906         sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1907         aurora_wait_CCR(bp->r[chip]);
1908
1909         sbus_writeb(CCR_CORCHG2, &bp->r[chip]->r[CD180_CCR]);
1910         aurora_wait_CCR(bp->r[chip]);
1911
1912         restore_flags(flags);
1913 #ifdef AURORA_DEBUG
1914         printk("aurora_send_break: end\n");
1915 #endif
1916 }
1917
1918 static int aurora_set_serial_info(struct Aurora_port * port,
1919                                   struct serial_struct * newinfo)
1920 {
1921         struct serial_struct tmp;
1922         struct Aurora_board *bp = port_Board(port);
1923         int change_speed;
1924         unsigned long flags;
1925
1926 #ifdef AURORA_DEBUG
1927         printk("aurora_set_serial_info: start\n");
1928 #endif
1929         if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1930                 return -EFAULT;
1931 #if 0   
1932         if ((tmp.irq != bp->irq) ||
1933             (tmp.port != bp->base) ||
1934             (tmp.type != PORT_CIRRUS) ||
1935             (tmp.baud_base != (bp->oscfreq + CD180_TPC/2) / CD180_TPC) ||
1936             (tmp.custom_divisor != 0) ||
1937             (tmp.xmit_fifo_size != CD180_NFIFO) ||
1938             (tmp.flags & ~AURORA_LEGAL_FLAGS))
1939                 return -EINVAL;
1940 #endif  
1941         
1942         change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1943                         (tmp.flags & ASYNC_SPD_MASK));
1944         
1945         if (!capable(CAP_SYS_ADMIN)) {
1946                 if ((tmp.close_delay != port->close_delay) ||
1947                     (tmp.closing_wait != port->closing_wait) ||
1948                     ((tmp.flags & ~ASYNC_USR_MASK) !=
1949                      (port->flags & ~ASYNC_USR_MASK)))  
1950                         return -EPERM;
1951                 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1952                                (tmp.flags & ASYNC_USR_MASK));
1953         } else  {
1954                 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1955                                (tmp.flags & ASYNC_FLAGS));
1956                 port->close_delay = tmp.close_delay;
1957                 port->closing_wait = tmp.closing_wait;
1958         }
1959         if (change_speed)  {
1960                 save_flags(flags); cli();
1961                 aurora_change_speed(bp, port);
1962                 restore_flags(flags);
1963         }
1964 #ifdef AURORA_DEBUG
1965         printk("aurora_set_serial_info: end\n");
1966 #endif
1967         return 0;
1968 }
1969
1970 extern int aurora_get_serial_info(struct Aurora_port * port,
1971                                   struct serial_struct * retinfo)
1972 {
1973         struct serial_struct tmp;
1974         struct Aurora_board *bp = port_Board(port);
1975         int error;
1976         
1977 #ifdef AURORA_DEBUG
1978         printk("aurora_get_serial_info: start\n");
1979 #endif
1980         error = verify_area(VERIFY_WRITE, (void *) retinfo, sizeof(tmp));
1981         if (error)
1982                 return error;
1983         
1984         memset(&tmp, 0, sizeof(tmp));
1985         tmp.type = PORT_CIRRUS;
1986         tmp.line = port - aurora_port;
1987         tmp.port = 0;
1988         tmp.irq  = bp->irq;
1989         tmp.flags = port->flags;
1990         tmp.baud_base = (bp->oscfreq + CD180_TPC/2) / CD180_TPC;
1991         tmp.close_delay = port->close_delay * HZ/100;
1992         tmp.closing_wait = port->closing_wait * HZ/100;
1993         tmp.xmit_fifo_size = CD180_NFIFO;
1994         copy_to_user(retinfo, &tmp, sizeof(tmp));
1995 #ifdef AURORA_DEBUG
1996 printk("aurora_get_serial_info: end\n");
1997 #endif
1998         return 0;
1999 }
2000
2001 static int aurora_ioctl(struct tty_struct * tty, struct file * filp, 
2002                     unsigned int cmd, unsigned long arg)
2003                     
2004 {
2005         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2006         int retval;
2007
2008 #ifdef AURORA_DEBUG
2009         printk("aurora_ioctl: start\n");
2010 #endif
2011         if (aurora_paranoia_check(port, tty->device, "aurora_ioctl"))
2012                 return -ENODEV;
2013         
2014         switch (cmd) {
2015         case TCSBRK:    /* SVID version: non-zero arg --> no break */
2016                 retval = tty_check_change(tty);
2017                 if (retval)
2018                         return retval;
2019                 tty_wait_until_sent(tty, 0);
2020                 if (!arg)
2021                         aurora_send_break(port, HZ/4);  /* 1/4 second */
2022                 return 0;
2023         case TCSBRKP:   /* support for POSIX tcsendbreak() */
2024                 retval = tty_check_change(tty);
2025                 if (retval)
2026                         return retval;
2027                 tty_wait_until_sent(tty, 0);
2028                 aurora_send_break(port, arg ? arg*(HZ/10) : HZ/4);
2029                 return 0;
2030         case TIOCGSOFTCAR:
2031                 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *)arg);
2032         case TIOCSSOFTCAR:
2033                 if (get_user(arg,(unsigned long *)arg))
2034                         return -EFAULT;
2035                 tty->termios->c_cflag =
2036                         ((tty->termios->c_cflag & ~CLOCAL) |
2037                          (arg ? CLOCAL : 0));
2038                 return 0;
2039         case TIOCMGET:
2040                 retval = verify_area(VERIFY_WRITE, (void *) arg,
2041                                     sizeof(unsigned int));
2042                 if (retval)
2043                         return retval;
2044                 return aurora_get_modem_info(port, (unsigned int *) arg);
2045         case TIOCMBIS:
2046         case TIOCMBIC:
2047         case TIOCMSET:
2048                 return aurora_set_modem_info(port, cmd, (unsigned int *) arg);
2049         case TIOCGSERIAL:       
2050                 return aurora_get_serial_info(port, (struct serial_struct *) arg);
2051         case TIOCSSERIAL:       
2052                 return aurora_set_serial_info(port, (struct serial_struct *) arg);
2053         default:
2054                 return -ENOIOCTLCMD;
2055         };
2056 #ifdef AURORA_DEBUG
2057         printk("aurora_ioctl: end\n");
2058 #endif
2059         return 0;
2060 }
2061
2062 static void aurora_throttle(struct tty_struct * tty)
2063 {
2064         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2065         struct Aurora_board *bp;
2066         unsigned long flags;
2067         unsigned char chip;
2068
2069 #ifdef AURORA_DEBUG
2070         printk("aurora_throttle: start\n");
2071 #endif
2072         if (aurora_paranoia_check(port, tty->device, "aurora_throttle"))
2073                 return;
2074         
2075         bp = port_Board(port);
2076         chip = AURORA_CD180(port_No(port));
2077         
2078         save_flags(flags); cli();
2079         port->MSVR &= ~bp->RTS;
2080         sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
2081         udelay(1);
2082         if (I_IXOFF(tty))  {
2083                 aurora_wait_CCR(bp->r[chip]);
2084                 sbus_writeb(CCR_SSCH2, &bp->r[chip]->r[CD180_CCR]);
2085                 aurora_wait_CCR(bp->r[chip]);
2086         }
2087         sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
2088         restore_flags(flags);
2089 #ifdef AURORA_DEBUG
2090         printk("aurora_throttle: end\n");
2091 #endif
2092 }
2093
2094 static void aurora_unthrottle(struct tty_struct * tty)
2095 {
2096         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2097         struct Aurora_board *bp;
2098         unsigned long flags;
2099         unsigned char chip;
2100
2101 #ifdef AURORA_DEBUG
2102         printk("aurora_unthrottle: start\n");
2103 #endif
2104         if (aurora_paranoia_check(port, tty->device, "aurora_unthrottle"))
2105                 return;
2106         
2107         bp = port_Board(port);
2108         
2109         chip = AURORA_CD180(port_No(port));
2110         
2111         save_flags(flags); cli();
2112         port->MSVR |= bp->RTS;
2113         sbus_writeb(port_No(port) & 7,
2114                     &bp->r[chip]->r[CD180_CAR]);
2115         udelay(1);
2116         if (I_IXOFF(tty))  {
2117                 aurora_wait_CCR(bp->r[chip]);
2118                 sbus_writeb(CCR_SSCH1,
2119                             &bp->r[chip]->r[CD180_CCR]);
2120                 aurora_wait_CCR(bp->r[chip]);
2121         }
2122         sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
2123         restore_flags(flags);
2124 #ifdef AURORA_DEBUG
2125         printk("aurora_unthrottle: end\n");
2126 #endif
2127 }
2128
2129 static void aurora_stop(struct tty_struct * tty)
2130 {
2131         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2132         struct Aurora_board *bp;
2133         unsigned long flags;
2134         unsigned char chip;
2135
2136 #ifdef AURORA_DEBUG
2137         printk("aurora_stop: start\n");
2138 #endif
2139         if (aurora_paranoia_check(port, tty->device, "aurora_stop"))
2140                 return;
2141         
2142         bp = port_Board(port);
2143         
2144         chip = AURORA_CD180(port_No(port));
2145         
2146         save_flags(flags); cli();
2147         port->SRER &= ~SRER_TXRDY;
2148         sbus_writeb(port_No(port) & 7,
2149                     &bp->r[chip]->r[CD180_CAR]);
2150         udelay(1);
2151         sbus_writeb(port->SRER,
2152                     &bp->r[chip]->r[CD180_SRER]);
2153         restore_flags(flags);
2154 #ifdef AURORA_DEBUG
2155         printk("aurora_stop: end\n");
2156 #endif
2157 }
2158
2159 static void aurora_start(struct tty_struct * tty)
2160 {
2161         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2162         struct Aurora_board *bp;
2163         unsigned long flags;
2164         unsigned char chip;
2165
2166 #ifdef AURORA_DEBUG
2167         printk("aurora_start: start\n");
2168 #endif
2169         if (aurora_paranoia_check(port, tty->device, "aurora_start"))
2170                 return;
2171         
2172         bp = port_Board(port);
2173         
2174         chip = AURORA_CD180(port_No(port));
2175         
2176         save_flags(flags); cli();
2177         if (port->xmit_cnt && port->xmit_buf && !(port->SRER & SRER_TXRDY))  {
2178                 port->SRER |= SRER_TXRDY;
2179                 sbus_writeb(port_No(port) & 7,
2180                             &bp->r[chip]->r[CD180_CAR]);
2181                 udelay(1);
2182                 sbus_writeb(port->SRER,
2183                             &bp->r[chip]->r[CD180_SRER]);
2184         }
2185         restore_flags(flags);
2186 #ifdef AURORA_DEBUG
2187         printk("aurora_start: end\n");
2188 #endif
2189 }
2190
2191 /*
2192  * This routine is called from the scheduler tqueue when the interrupt
2193  * routine has signalled that a hangup has occurred.  The path of
2194  * hangup processing is:
2195  *
2196  *      serial interrupt routine -> (scheduler tqueue) ->
2197  *      do_aurora_hangup() -> tty->hangup() -> aurora_hangup()
2198  * 
2199  */
2200 static void do_aurora_hangup(void *private_)
2201 {
2202         struct Aurora_port      *port = (struct Aurora_port *) private_;
2203         struct tty_struct       *tty;
2204
2205 #ifdef AURORA_DEBUG
2206         printk("do_aurora_hangup: start\n");
2207 #endif
2208         tty = port->tty;
2209         if (tty != NULL) {
2210                 tty_hangup(tty);        /* FIXME: module removal race - AKPM */
2211 #ifdef AURORA_DEBUG
2212                 printk("do_aurora_hangup: end\n");
2213 #endif
2214         }
2215         MOD_DEC_USE_COUNT;
2216 }
2217
2218 static void aurora_hangup(struct tty_struct * tty)
2219 {
2220         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2221         struct Aurora_board *bp;
2222                                 
2223 #ifdef AURORA_DEBUG
2224         printk("aurora_hangup: start\n");
2225 #endif
2226         if (aurora_paranoia_check(port, tty->device, "aurora_hangup"))
2227                 return;
2228         
2229         bp = port_Board(port);
2230         
2231         aurora_shutdown_port(bp, port);
2232         port->event = 0;
2233         port->count = 0;
2234         port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
2235         port->tty = 0;
2236         wake_up_interruptible(&port->open_wait);
2237 #ifdef AURORA_DEBUG
2238         printk("aurora_hangup: end\n");
2239 #endif
2240 }
2241
2242 static void aurora_set_termios(struct tty_struct * tty, struct termios * old_termios)
2243 {
2244         struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2245         unsigned long flags;
2246
2247 #ifdef AURORA_DEBUG
2248         printk("aurora_set_termios: start\n");
2249 #endif
2250         if (aurora_paranoia_check(port, tty->device, "aurora_set_termios"))
2251                 return;
2252         
2253         if (tty->termios->c_cflag == old_termios->c_cflag &&
2254             tty->termios->c_iflag == old_termios->c_iflag)
2255                 return;
2256
2257         save_flags(flags); cli();
2258         aurora_change_speed(port_Board(port), port);
2259         restore_flags(flags);
2260
2261         if ((old_termios->c_cflag & CRTSCTS) &&
2262             !(tty->termios->c_cflag & CRTSCTS)) {
2263                 tty->hw_stopped = 0;
2264                 aurora_start(tty);
2265         }
2266 #ifdef AURORA_DEBUG
2267         printk("aurora_set_termios: end\n");
2268 #endif
2269 }
2270
2271 static void do_aurora_bh(void)
2272 {
2273          run_task_queue(&tq_aurora);
2274 }
2275
2276 static void do_softint(void *private_)
2277 {
2278         struct Aurora_port      *port = (struct Aurora_port *) private_;
2279         struct tty_struct       *tty;
2280
2281 #ifdef AURORA_DEBUG
2282         printk("do_softint: start\n");
2283 #endif
2284         tty = port->tty;
2285         if (tty == NULL)
2286                 return;
2287
2288         if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
2289                 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2290                     tty->ldisc.write_wakeup)
2291                         (tty->ldisc.write_wakeup)(tty);
2292                 wake_up_interruptible(&tty->write_wait);
2293         }
2294 #ifdef AURORA_DEBUG
2295         printk("do_softint: end\n");
2296 #endif
2297 }
2298
2299 static int aurora_init_drivers(void)
2300 {
2301         int error;
2302         int i;
2303
2304 #ifdef AURORA_DEBUG
2305         printk("aurora_init_drivers: start\n");
2306 #endif
2307         tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL);
2308         if (tmp_buf == NULL) {
2309                 printk(KERN_ERR "aurora: Couldn't get free page.\n");
2310                 return 1;
2311         }
2312         init_bh(AURORA_BH, do_aurora_bh);
2313 /*      memset(IRQ_to_board, 0, sizeof(IRQ_to_board));*/
2314         memset(&aurora_driver, 0, sizeof(aurora_driver));
2315         aurora_driver.magic = TTY_DRIVER_MAGIC;
2316         aurora_driver.name = "ttyA";
2317         aurora_driver.major = AURORA_MAJOR;
2318         aurora_driver.num = AURORA_TNPORTS;
2319         aurora_driver.type = TTY_DRIVER_TYPE_SERIAL;
2320         aurora_driver.subtype = AURORA_TYPE_NORMAL;
2321         aurora_driver.init_termios = tty_std_termios;
2322         aurora_driver.init_termios.c_cflag =
2323                 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2324         aurora_driver.flags = TTY_DRIVER_REAL_RAW;
2325         aurora_driver.refcount = &aurora_refcount;
2326         aurora_driver.table = aurora_table;
2327         aurora_driver.termios = aurora_termios;
2328         aurora_driver.termios_locked = aurora_termios_locked;
2329
2330         aurora_driver.open  = aurora_open;
2331         aurora_driver.close = aurora_close;
2332         aurora_driver.write = aurora_write;
2333         aurora_driver.put_char = aurora_put_char;
2334         aurora_driver.flush_chars = aurora_flush_chars;
2335         aurora_driver.write_room = aurora_write_room;
2336         aurora_driver.chars_in_buffer = aurora_chars_in_buffer;
2337         aurora_driver.flush_buffer = aurora_flush_buffer;
2338         aurora_driver.ioctl = aurora_ioctl;
2339         aurora_driver.throttle = aurora_throttle;
2340         aurora_driver.unthrottle = aurora_unthrottle;
2341         aurora_driver.set_termios = aurora_set_termios;
2342         aurora_driver.stop = aurora_stop;
2343         aurora_driver.start = aurora_start;
2344         aurora_driver.hangup = aurora_hangup;
2345
2346         error = tty_register_driver(&aurora_driver);
2347         if (error) {
2348                 free_page((unsigned long) tmp_buf);
2349                 printk(KERN_ERR "aurora: Couldn't register aurora driver, error = %d\n",
2350                        error);
2351                 return 1;
2352         }
2353         
2354         memset(aurora_port, 0, sizeof(aurora_port));
2355         for (i = 0; i < AURORA_TNPORTS; i++)  {
2356                 aurora_port[i].normal_termios  = aurora_driver.init_termios;
2357                 aurora_port[i].magic = AURORA_MAGIC;
2358                 aurora_port[i].tqueue.routine = do_softint;
2359                 aurora_port[i].tqueue.data = &aurora_port[i];
2360                 aurora_port[i].tqueue_hangup.routine = do_aurora_hangup;
2361                 aurora_port[i].tqueue_hangup.data = &aurora_port[i];
2362                 aurora_port[i].close_delay = 50 * HZ/100;
2363                 aurora_port[i].closing_wait = 3000 * HZ/100;
2364                 init_waitqueue_head(&aurora_port[i].open_wait);
2365                 init_waitqueue_head(&aurora_port[i].close_wait);
2366         }
2367 #ifdef AURORA_DEBUG
2368         printk("aurora_init_drivers: end\n");
2369 #endif
2370         return 0;
2371 }
2372
2373 static void aurora_release_drivers(void)
2374 {
2375 #ifdef AURORA_DEBUG
2376         printk("aurora_release_drivers: start\n");
2377 #endif
2378         free_page((unsigned long)tmp_buf);
2379         tty_unregister_driver(&aurora_driver);
2380 #ifdef AURORA_DEBUG
2381         printk("aurora_release_drivers: end\n");
2382 #endif
2383 }
2384
2385 /*
2386  * Called at boot time.
2387  *
2388  * You can specify IO base for up to RC_NBOARD cards,
2389  * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
2390  * Note that there will be no probing at default
2391  * addresses in this case.
2392  *
2393  */
2394 void __init aurora_setup(char *str, int *ints)
2395 {
2396         int i;
2397
2398         for(i=0;(i<ints[0])&&(i<4);i++) {
2399                 if (ints[i+1]) irqs[i]=ints[i+1];
2400                 }
2401 }
2402
2403 static int __init aurora_real_init(void)
2404 {
2405         int found;
2406         int i;
2407
2408         printk(KERN_INFO "aurora: Driver starting.\n");
2409         if(aurora_init_drivers())
2410                 return -EIO;
2411         found = aurora_probe();
2412         if(!found) {
2413                 aurora_release_drivers();
2414                 printk(KERN_INFO "aurora: No Aurora Multiport boards detected.\n");
2415                 return -EIO;
2416         } else {
2417                 printk(KERN_INFO "aurora: %d boards found.\n", found);
2418         }
2419         for (i = 0; i < found; i++) {
2420                 int ret = aurora_setup_board(&aurora_board[i]);
2421
2422                 if (ret) {
2423 #ifdef AURORA_DEBUG
2424                         printk(KERN_ERR "aurora_init: error aurora_setup_board ret %d\n",
2425                                ret);
2426 #endif
2427                         return ret;
2428                 }
2429         }
2430         return 0;
2431 }
2432
2433 int irq  = 0;
2434 int irq1 = 0;
2435 int irq2 = 0;
2436 int irq3 = 0;
2437 MODULE_PARM(irq , "i");
2438 MODULE_PARM(irq1, "i");
2439 MODULE_PARM(irq2, "i");
2440 MODULE_PARM(irq3, "i");
2441
2442 static int __init aurora_init(void) 
2443 {
2444         if (irq ) irqs[0]=irq ;
2445         if (irq1) irqs[1]=irq1;
2446         if (irq2) irqs[2]=irq2;
2447         if (irq3) irqs[3]=irq3;
2448         return aurora_real_init();
2449 }
2450         
2451 static void __exit aurora_cleanup(void)
2452 {
2453         int i;
2454         
2455 #ifdef AURORA_DEBUG
2456 printk("cleanup_module: aurora_release_drivers\n");
2457 #endif
2458
2459         aurora_release_drivers();
2460         for (i = 0; i < AURORA_NBOARD; i++)
2461                 if (aurora_board[i].flags & AURORA_BOARD_PRESENT) {
2462                         aurora_shutdown_board(&aurora_board[i]);
2463                         aurora_release_io_range(&aurora_board[i]);
2464                 }
2465 }
2466
2467 module_init(aurora_init);
2468 module_exit(aurora_cleanup);
2469 MODULE_LICENSE("GPL");