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