Import 2.3.16
[davej-history.git] / drivers / sbus / char / aurora.c
blob5ec3107cb1b5cc92e8a692c7256ca2e3403e4cb0
1 /*
2 * linux/drivers/sbus/char/aurora.c -- Aurora multiport driver
4 * Copyright (c) 1999 by Oliver Aldulea (oli@bv.ro)
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.
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.
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.
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.
28 * Revision 1.0
30 * This is the first public release.
32 * Most of the information you need is in the aurora.h file. Please
33 * read that file before reading this one.
35 * Several parts of the code do not have comments yet.
38 #include <linux/module.h>
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>
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>
67 #include "aurora.h"
68 #include "cd180.h"
70 unsigned char irqs[4] = {
71 0, 0, 0, 0
74 #ifdef AURORA_INT_DEBUG
75 int irqhit=0;
76 #endif
78 #ifndef MIN
79 #define MIN(a,b) ((a) < (b) ? (a) : (b))
80 #endif
82 #define AURORA_TYPE_NORMAL 1
84 static struct tty_driver aurora_driver;
85 static struct Aurora_board aurora_board[AURORA_NBOARD] = {
86 {0,},
89 static struct Aurora_port aurora_port[AURORA_TNPORTS] = {
90 { 0, },
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, };
101 DECLARE_TASK_QUEUE(tq_aurora);
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.
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,
113 static inline int aurora_paranoia_check(struct Aurora_port const * port,
114 kdev_t device, const char *routine)
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";
122 if (!port) {
123 printk(badinfo, kdevname(device), routine);
124 return 1;
126 if (port->magic != AURORA_MAGIC) {
127 printk(badmagic, kdevname(device), routine);
128 return 1;
130 #endif
131 return 0;
136 * Service functions for aurora driver.
140 /* Get board number from pointer */
141 extern inline int board_No (struct Aurora_board const * bp)
143 return bp - aurora_board;
146 /* Get port number from pointer */
147 extern inline int port_No (struct Aurora_port const * port)
149 return AURORA_PORT(port - aurora_port);
152 /* Get pointer to board from pointer to port */
153 extern inline struct Aurora_board * port_Board(struct Aurora_port const * port)
155 return &aurora_board[AURORA_BOARD(port - aurora_port)];
158 /* Wait for Channel Command Register ready */
159 extern inline void aurora_wait_CCR(struct aurora_reg128 * r)
161 unsigned long delay;
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 (!r->r[CD180_CCR])
169 return;
170 printk(KERN_DEBUG "aurora: Timeout waiting for CCR.\n");
174 * aurora probe functions.
177 /* Must be called with enabled interrupts */
178 extern inline void aurora_long_delay(unsigned long delay)
180 unsigned long i;
181 #ifdef AURORA_DEBUG
182 printk("aurora_long_delay: start\n");
183 #endif
184 for (i = jiffies + delay; i > jiffies; ) ;
185 #ifdef AURORA_DEBUG
186 printk("aurora_long_delay: end\n");
187 #endif
190 /* Reset and setup CD180 chip */
191 static int aurora_init_CD180(struct Aurora_board * bp, int chip)
193 unsigned long flags;
194 int id;
196 #ifdef AURORA_DEBUG
197 printk("aurora_init_CD180: start %d:%d\n",board_No(bp),chip);
198 #endif
199 save_flags(flags); cli();
200 bp->r[chip]->r[CD180_CAR]=0;
201 bp->r[chip]->r[CD180_GSVR]=0;
202 aurora_wait_CCR(bp->r[chip]); /* Wait for CCR ready */
203 bp->r[chip]->r[CD180_CCR]=CCR_HARDRESET; /* Reset CD180 chip */
204 udelay(1);
205 sti();
206 id=1000;
207 while((--id)&&(bp->r[chip]->r[CD180_GSVR]!=0xff))udelay(100);
208 if(!id) {
209 printk(KERN_ERR "aurora%d: Chip %d failed init.\n",board_No(bp),chip);
210 restore_flags(flags);
211 return(-1);
213 cli();
214 bp->r[chip]->r[CD180_GSVR]=(board_No(bp)<<5)|((chip+1)<<3); /* Set ID for this chip */
215 bp->r[chip]->r[CD180_MSMR]=0x80|bp->ACK_MINT; /* Prio for modem intr */
216 bp->r[chip]->r[CD180_TSMR]=0x80|bp->ACK_TINT; /* Prio for transmitter intr */
217 bp->r[chip]->r[CD180_RSMR]=0x80|bp->ACK_RINT; /* Prio for receiver intr */
218 /* Setting up prescaler. We need 4 tick per 1 ms */
219 bp->r[chip]->r[CD180_PPRH]=(bp->oscfreq/(1000000/AURORA_TPS)) >> 8;
220 bp->r[chip]->r[CD180_PPRL]=(bp->oscfreq/(1000000/AURORA_TPS)) & 0xff;
222 bp->r[chip]->r[CD180_SRCR]=SRCR_AUTOPRI|SRCR_GLOBPRI;
224 id=bp->r[chip]->r[CD180_GFRCR];
225 printk(KERN_INFO "aurora%d: Chip %d id %02x: ",board_No(bp),chip,id);
226 if(bp->r[chip]->r[CD180_SRCR]&128)
227 switch(id){
228 case 0x82:printk("CL-CD1864 rev A\n");break;
229 case 0x83:printk("CL-CD1865 rev A\n");break;
230 case 0x84:printk("CL-CD1865 rev B\n");break;
231 case 0x85:printk("CL-CD1865 rev C\n");break;
232 default:printk("Unknown.\n");
233 }else
234 switch(id){
235 case 0x81:printk("CL-CD180 rev B\n");break;
236 case 0x82:printk("CL-CD180 rev C\n");break;
237 default:printk("Unknown.\n");
239 restore_flags(flags);
240 #ifdef AURORA_DEBUG
241 printk("aurora_init_CD180: end\n");
242 #endif
243 return 0;
246 static int valid_irq(unsigned char irq)
248 int i;
249 for(i=0;i<TYPE_1_IRQS;i++)
250 if (type_1_irq[i]==irq) return 1;
251 return 0;
254 static void aurora_interrupt(int irq, void * dev_id, struct pt_regs * regs);
256 /* Main probing routine, also sets irq. */
257 static int aurora_probe(void) {
258 struct linux_sbus *sbus;
259 struct linux_sbus_device *sdev;
260 int grrr;
261 char buf[30];
262 int bn=0;
263 struct Aurora_board *bp;
265 for_each_sbus(sbus) {
266 for_each_sbusdev(sdev, sbus) {
267 /* printk("Try: %x %s\n",sdev,sdev->prom_name);*/
268 if (!strcmp(sdev->prom_name, "sio16")) {
269 #ifdef AURORA_DEBUG
270 printk(KERN_INFO "aurora: sio16 at %p\n",sdev);
271 #endif
272 prom_apply_sbus_ranges(sdev->my_bus, sdev->reg_addrs, sdev->num_registers, sdev);
273 if((sdev->reg_addrs[0].reg_size!=1)&&(sdev->reg_addrs[1].reg_size!=128)&&
274 (sdev->reg_addrs[2].reg_size!=128)&&(sdev->reg_addrs[3].reg_size!=4)){
275 printk(KERN_ERR "aurora%d: registers' sizes do not match.\n",bn);
276 break;
278 bp=&aurora_board[bn];
279 bp->r0 = (struct aurora_reg1 *) sparc_alloc_io(sdev->reg_addrs[0].phys_addr, 0,
280 sdev->reg_addrs[0].reg_size, "sio16",sdev->reg_addrs[0].which_io, 0x0);
281 if (!bp->r0) {
282 printk(KERN_ERR "aurora%d: can't map reg_addrs[0]\n",bn);
283 break;
285 #ifdef AURORA_DEBUG
286 printk("Map reg 0: %x\n",bp->r0);
287 #endif
288 bp->r[0] = (struct aurora_reg128 *) sparc_alloc_io(sdev->reg_addrs[1].phys_addr, 0,
289 sdev->reg_addrs[1].reg_size, "sio16", sdev->reg_addrs[1].which_io, 0x0);
290 if (!bp->r[0]) {
291 printk(KERN_ERR "aurora%d: can't map reg_addrs[1]\n",bn);
292 break;
294 #ifdef AURORA_DEBUG
295 printk("Map reg 1: %x\n",bp->r[0]);
296 #endif
297 bp->r[1] = (struct aurora_reg128 *) sparc_alloc_io(sdev->reg_addrs[2].phys_addr, 0,
298 sdev->reg_addrs[2].reg_size, "sio16", sdev->reg_addrs[2].which_io, 0x0);
299 if (!bp->r[1]) {
300 printk(KERN_ERR "aurora%d: can't map reg_addrs[2]\n",bn);
301 break;
303 #ifdef AURORA_DEBUG
304 printk("Map reg 2: %x\n",bp->r[1]);
305 #endif
306 bp->r3 = (struct aurora_reg4 *) sparc_alloc_io(sdev->reg_addrs[3].phys_addr, 0,
307 sdev->reg_addrs[3].reg_size, "sio16", sdev->reg_addrs[3].which_io, 0x0);
308 if (!bp->r3) {
309 printk(KERN_ERR "aurora%d: can't map reg_addrs[3]\n",bn);
310 break;
312 #ifdef AURORA_DEBUG
313 printk("Map reg 3: %x\n",bp->r3);
314 #endif
315 /* Variables setup */
316 bp->flags = 0;
317 #ifdef AURORA_DEBUG
318 grrr=prom_getint(sdev->prom_node,"intr");
319 printk("intr pri %d\n",grrr);
320 #endif
321 if ((bp->irq=irqs[bn]) && valid_irq(bp->irq) &&
322 !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
323 free_irq(bp->irq|0x30, bp);
324 } else
325 if ((bp->irq=prom_getint(sdev->prom_node, "bintr")) && valid_irq(bp->irq) &&
326 !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
327 free_irq(bp->irq|0x30, bp);
328 } else
329 if ((bp->irq=prom_getint(sdev->prom_node, "intr")) && valid_irq(bp->irq) &&
330 !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
331 free_irq(bp->irq|0x30, bp);
332 } else
333 for(grrr=0;grrr<TYPE_1_IRQS;grrr++) {
334 if ((bp->irq=type_1_irq[grrr])&&!request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
335 free_irq(bp->irq|0x30, bp);
336 break;
337 } else {
338 printk(KERN_ERR "aurora%d: Could not get an irq for this board !!!\n",bn);
339 bp->flags=0xff;
342 if(bp->flags==0xff)break;
343 printk(KERN_INFO "aurora%d: irq %d\n",bn,bp->irq&0x0f);
344 buf[0]=0;
345 grrr=prom_getproperty(sdev->prom_node,"dtr_rts",buf,sizeof(buf));
346 if(!strcmp(buf,"swapped")){
347 printk(KERN_INFO "aurora%d: Swapped DTR and RTS\n",bn);
348 bp->DTR=MSVR_RTS;
349 bp->RTS=MSVR_DTR;
350 bp->MSVDTR=CD180_MSVRTS;
351 bp->MSVRTS=CD180_MSVDTR;
352 bp->flags|=AURORA_BOARD_DTR_FLOW_OK;
353 }else{
354 #ifdef AURORA_FORCE_DTR_FLOW
355 printk(KERN_INFO "aurora%d: Forcing swapped DTR-RTS\n",bn);
356 bp->DTR=MSVR_RTS;
357 bp->RTS=MSVR_DTR;
358 bp->MSVDTR=CD180_MSVRTS;
359 bp->MSVRTS=CD180_MSVDTR;
360 bp->flags|=AURORA_BOARD_DTR_FLOW_OK;
361 #else
362 printk(KERN_INFO "aurora%d: Normal DTR and RTS\n",bn);
363 bp->DTR=MSVR_DTR;
364 bp->RTS=MSVR_RTS;
365 bp->MSVDTR=CD180_MSVDTR;
366 bp->MSVRTS=CD180_MSVRTS;
367 #endif
369 bp->oscfreq=prom_getint(sdev->prom_node,"clk")*100;
370 printk(KERN_INFO "aurora%d: Oscillator: %d Hz\n",bn,bp->oscfreq);
371 grrr=prom_getproperty(sdev->prom_node,"chip",buf,sizeof(buf));
372 printk(KERN_INFO "aurora%d: Chips: %s\n",bn,buf);
373 grrr=prom_getproperty(sdev->prom_node,"manu",buf,sizeof(buf));
374 printk(KERN_INFO "aurora%d: Manufacturer: %s\n",bn,buf);
375 grrr=prom_getproperty(sdev->prom_node,"model",buf,sizeof(buf));
376 printk(KERN_INFO "aurora%d: Model: %s\n",bn,buf);
377 grrr=prom_getproperty(sdev->prom_node,"rev",buf,sizeof(buf));
378 printk(KERN_INFO "aurora%d: Revision: %s\n",bn,buf);
379 grrr=prom_getproperty(sdev->prom_node,"mode",buf,sizeof(buf));
380 printk(KERN_INFO "aurora%d: Mode: %s\n",bn,buf);
381 #ifdef MODULE
382 bp->count=0;
383 #endif
384 bp->flags = AURORA_BOARD_PRESENT;
385 /* hardware ack */
386 bp->ACK_MINT=1;
387 bp->ACK_TINT=2;
388 bp->ACK_RINT=3;
389 bn++;
393 return bn;
396 static void aurora_release_io_range(struct Aurora_board *bp)
398 sparc_free_io(bp->r0,1);
399 sparc_free_io(bp->r[0],128);
400 sparc_free_io(bp->r[1],128);
401 sparc_free_io(bp->r3,4);
404 extern inline void aurora_mark_event(struct Aurora_port * port, int event)
406 #ifdef AURORA_DEBUG
407 printk("aurora_mark_event: start\n");
408 #endif
409 set_bit(event, &port->event);
410 queue_task(&port->tqueue, &tq_aurora);
411 mark_bh(AURORA_BH);
412 #ifdef AURORA_DEBUG
413 printk("aurora_mark_event: end\n");
414 #endif
417 extern inline struct Aurora_port * aurora_get_port(struct Aurora_board const * bp,
418 int chip, unsigned char const * what)
420 unsigned char channel;
421 struct Aurora_port * port;
423 channel = (chip<<3)|((bp->r[chip]->r[CD180_GSCR]&GSCR_CHAN)>>GSCR_CHAN_OFF);
424 port = &aurora_port[board_No(bp) * AURORA_NPORT * AURORA_NCD180 + channel];
425 if (port->flags & ASYNC_INITIALIZED) {
426 return port;
428 printk(KERN_DEBUG "aurora%d: %s interrupt from invalid port %d\n",
429 board_No(bp), what, channel);
430 return NULL;
433 extern inline void aurora_receive_exc(struct Aurora_board const * bp, int chip)
435 struct Aurora_port *port;
436 struct tty_struct *tty;
437 unsigned char status;
438 unsigned char ch;
440 if (!(port = aurora_get_port(bp, chip, "Receive_x")))
441 return;
443 tty = port->tty;
444 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
445 #ifdef AURORA_INTNORM
446 printk("aurora%d: port %d: Working around flip buffer overflow.\n",
447 board_No(bp), port_No(port));
448 #endif
449 return;
452 #ifdef AURORA_REPORT_OVERRUN
453 status = bp->r[chip]->r[CD180_RCSR];
454 if (status & RCSR_OE) {
455 port->overrun++;
456 #if 1
457 printk("aurora%d: port %d: Overrun. Total %ld overruns.\n",
458 board_No(bp), port_No(port), port->overrun);
459 #endif
461 status &= port->mark_mask;
462 #else
463 status = bp->r[chip]->r[CD180_RCSR] & port->mark_mask;
464 #endif
465 ch = bp->r[chip]->r[CD180_RDR];
466 if (!status) {
467 return;
469 if (status & RCSR_TOUT) {
470 /* printk("aurora%d: port %d: Receiver timeout. Hardware problems ?\n",
471 board_No(bp), port_No(port));*/
472 return;
474 } else if (status & RCSR_BREAK) {
475 printk(KERN_DEBUG "aurora%d: port %d: Handling break...\n",
476 board_No(bp), port_No(port));
477 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
478 if (port->flags & ASYNC_SAK)
479 do_SAK(tty);
481 } else if (status & RCSR_PE)
482 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
484 else if (status & RCSR_FE)
485 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
487 else if (status & RCSR_OE)
488 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
490 else
491 *tty->flip.flag_buf_ptr++ = 0;
493 *tty->flip.char_buf_ptr++ = ch;
494 tty->flip.count++;
495 queue_task(&tty->flip.tqueue, &tq_timer);
498 extern inline void aurora_receive(struct Aurora_board const * bp, int chip)
500 struct Aurora_port *port;
501 struct tty_struct *tty;
502 unsigned char count,cnt;
504 if (!(port = aurora_get_port(bp, chip, "Receive")))
505 return;
507 tty = port->tty;
509 count = bp->r[chip]->r[CD180_RDCR];
511 #ifdef AURORA_REPORT_FIFO
512 port->hits[count > 8 ? 9 : count]++;
513 #endif
515 while (count--) {
516 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
517 #ifdef AURORA_INTNORM
518 printk("aurora%d: port %d: Working around flip buffer overflow.\n",
519 board_No(bp), port_No(port));
520 #endif
521 break;
523 cnt=bp->r[chip]->r[CD180_RDR];
524 *tty->flip.char_buf_ptr++ = cnt;
525 *tty->flip.flag_buf_ptr++ = 0;
526 tty->flip.count++;
528 queue_task(&tty->flip.tqueue, &tq_timer);
531 extern inline void aurora_transmit(struct Aurora_board const * bp, int chip)
533 struct Aurora_port *port;
534 struct tty_struct *tty;
535 unsigned char count;
538 if (!(port = aurora_get_port(bp, chip, "Transmit")))
539 return;
541 tty = port->tty;
543 if (port->SRER & SRER_TXEMPTY) {
544 /* FIFO drained */
545 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
546 udelay(1);
547 port->SRER &= ~SRER_TXEMPTY;
548 bp->r[chip]->r[CD180_SRER]=port->SRER;
549 return;
552 if ((port->xmit_cnt <= 0 && !port->break_length)
553 || tty->stopped || tty->hw_stopped) {
554 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
555 udelay(1);
556 port->SRER &= ~SRER_TXRDY;
557 bp->r[chip]->r[CD180_SRER]=port->SRER;
558 return;
561 if (port->break_length) {
562 if (port->break_length > 0) {
563 if (port->COR2 & COR2_ETC) {
564 bp->r[chip]->r[CD180_TDR]=CD180_C_ESC;
565 bp->r[chip]->r[CD180_TDR]=CD180_C_SBRK;
566 port->COR2 &= ~COR2_ETC;
568 count = MIN(port->break_length, 0xff);
569 bp->r[chip]->r[CD180_TDR]=CD180_C_ESC;
570 bp->r[chip]->r[CD180_TDR]=CD180_C_DELAY;
571 bp->r[chip]->r[CD180_TDR]=count;
572 if (!(port->break_length -= count))
573 port->break_length--;
574 } else {
575 bp->r[chip]->r[CD180_TDR]=CD180_C_ESC;
576 bp->r[chip]->r[CD180_TDR]=CD180_C_EBRK;
577 bp->r[chip]->r[CD180_COR2]=port->COR2;
578 aurora_wait_CCR(bp->r[chip]);
579 bp->r[chip]->r[CD180_CCR]=CCR_CORCHG2;
580 port->break_length = 0;
582 return;
585 count = CD180_NFIFO;
586 do {
587 bp->r[chip]->r[CD180_TDR]=port->xmit_buf[port->xmit_tail++];
588 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
589 if (--port->xmit_cnt <= 0)
590 break;
591 } while (--count > 0);
593 if (port->xmit_cnt <= 0) {
594 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
595 udelay(1);
596 port->SRER &= ~SRER_TXRDY;
597 bp->r[chip]->r[CD180_SRER]=port->SRER;
599 if (port->xmit_cnt <= port->wakeup_chars)
600 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
603 extern inline void aurora_check_modem(struct Aurora_board const * bp, int chip)
605 struct Aurora_port *port;
606 struct tty_struct *tty;
607 unsigned char mcr;
609 if (!(port = aurora_get_port(bp, chip, "Modem")))
610 return;
612 tty = port->tty;
614 mcr = bp->r[chip]->r[CD180_MCR];
615 if (mcr & MCR_CDCHG) {
616 if (bp->r[chip]->r[CD180_MSVR] & MSVR_CD)
617 wake_up_interruptible(&port->open_wait);
618 else if (!((port->flags & ASYNC_CALLOUT_ACTIVE) &&
619 (port->flags & ASYNC_CALLOUT_NOHUP)))
620 queue_task(&port->tqueue_hangup,
621 &tq_scheduler);
624 /* 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
625 * Aurora didn't made any boards with CTS or DSR broken...
627 /* #ifdef AURORA_BRAIN_DAMAGED_CTS
628 if (mcr & MCR_CTSCHG) {
629 if (aurora_in(bp, CD180_MSVR) & MSVR_CTS) {
630 tty->hw_stopped = 0;
631 port->SRER |= SRER_TXRDY;
632 if (port->xmit_cnt <= port->wakeup_chars)
633 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
634 } else {
635 tty->hw_stopped = 1;
636 port->SRER &= ~SRER_TXRDY;
638 bp->r[chip]->r[CD180_SRER, port->SRER);
640 if (mcr & MCR_DSRCHG) {
641 if (aurora_in(bp, CD180_MSVR) & MSVR_DSR) {
642 tty->hw_stopped = 0;
643 port->SRER |= SRER_TXRDY;
644 if (port->xmit_cnt <= port->wakeup_chars)
645 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
646 } else {
647 tty->hw_stopped = 1;
648 port->SRER &= ~SRER_TXRDY;
650 bp->r[chip]->r[CD180_SRER, port->SRER);
652 #endif AURORA_BRAIN_DAMAGED_CTS */
654 /* Clear change bits */
655 bp->r[chip]->r[CD180_MCR]=0;
658 /* The main interrupt processing routine */
659 static void aurora_interrupt(int irq, void * dev_id, struct pt_regs * regs)
661 unsigned char status;
662 unsigned char ack,chip/*,chip_id*/;
663 struct Aurora_board * bp = (struct Aurora_board *) dev_id;
664 unsigned long loop=0;
666 #ifdef AURORA_INT_DEBUG
667 printk("IRQ%d %d\n",irq,++irqhit);
668 #ifdef AURORA_FLOODPRO
669 if (irqhit>=AURORA_FLOODPRO)
670 bp->r0->r=8;
671 #endif
672 #endif
674 /* old bp = IRQ_to_board[irq&0x0f];*/
676 if (!bp || !(bp->flags & AURORA_BOARD_ACTIVE)) {
677 return;
680 /* The while() below takes care of this.
681 status=bp->r[0]->r[CD180_SRSR];
682 #ifdef AURORA_INT_DEBUG
683 printk("mumu: %02x\n",status);
684 #endif
685 if (!(status&SRSR_ANYINT)) return; * Nobody has anything to say, so exit *
687 while ((loop++ < 48)&&(status=bp->r[0]->r[CD180_SRSR]&SRSR_ANYINT)){
688 #ifdef AURORA_INT_DEBUG
689 printk("SRSR: %02x\n",status);
690 #endif
691 if (status&SRSR_REXT) {
692 ack=bp->r3->r[bp->ACK_RINT];
693 #ifdef AURORA_INT_DEBUG
694 printk("R-ACK %02x\n",ack);
695 #endif
696 if ((ack>>5)==board_No(bp)) {
697 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
698 if ((ack&GSVR_ITMASK)==GSVR_IT_RGD) {
699 aurora_receive(bp,chip);
700 bp->r[chip]->r[CD180_EOSRR]=0;
701 } else
702 if ((ack&GSVR_ITMASK)==GSVR_IT_REXC) {
703 aurora_receive_exc(bp,chip);
704 bp->r[chip]->r[CD180_EOSRR]=0;
708 } else
709 if (status&SRSR_TEXT) {
710 ack=bp->r3->r[bp->ACK_TINT];
711 #ifdef AURORA_INT_DEBUG
712 printk("T-ACK %02x\n",ack);
713 #endif
714 if ((ack>>5)==board_No(bp)) {
715 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
716 if ((ack&GSVR_ITMASK)==GSVR_IT_TX) {
717 aurora_transmit(bp,chip);
718 bp->r[chip]->r[CD180_EOSRR]=0;
722 } else
723 if (status&SRSR_MEXT) {
724 ack=bp->r3->r[bp->ACK_MINT];
725 #ifdef AURORA_INT_DEBUG
726 printk("M-ACK %02x\n",ack);
727 #endif
728 if ((ack>>5)==board_No(bp)) {
729 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
730 if ((ack&GSVR_ITMASK)==GSVR_IT_MDM) {
731 aurora_check_modem(bp,chip);
732 bp->r[chip]->r[CD180_EOSRR]=0;
738 /* I guess this faster code can be used with CD1865, using AUROPRI and GLOBPRI.
739 while ((loop++ < 48)&&(status=bp->r[0]->r[CD180_SRSR]&SRSR_ANYINT)){
740 #ifdef AURORA_INT_DEBUG
741 printk("SRSR: %02x\n",status);
742 #endif
743 ack=bp->r3->r[0];
744 #ifdef AURORA_INT_DEBUG
745 printk("ACK: %02x\n",ack);
746 #endif
747 if ((ack>>5)==board_No(bp)) {
748 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
749 ack&=GSVR_ITMASK;
750 if (ack==GSVR_IT_RGD) {
751 aurora_receive(bp,chip);
752 bp->r[chip]->r[CD180_EOSRR]=0;
753 } else
754 if (ack==GSVR_IT_REXC) {
755 aurora_receive_exc(bp,chip);
756 bp->r[chip]->r[CD180_EOSRR]=0;
757 } else
758 if (ack==GSVR_IT_TX) {
759 aurora_transmit(bp,chip);
760 bp->r[chip]->r[CD180_EOSRR]=0;
761 } else
762 if (ack==GSVR_IT_MDM) {
763 aurora_check_modem(bp,chip);
764 bp->r[chip]->r[CD180_EOSRR]=0;
770 /* This is the old handling routine, used in riscom8 for only one CD180. I keep it here for reference.
771 for(chip=0;chip<AURORA_NCD180;chip++){
772 chip_id=(board_No(bp)<<5)|((chip+1)<<3);
773 loop=0;
774 while ((loop++ < 1) && ((status = bp->r[chip]->r[CD180_SRSR]) &
775 (SRSR_TEXT | SRSR_MEXT | SRSR_REXT))) {
777 if (status & SRSR_REXT) {
778 ack = bp->r3->r[bp->ACK_RINT];
779 if (ack == (chip_id | GSVR_IT_RGD)){
780 #ifdef AURORA_INTMSG
781 printk("RX ACK\n");
782 #endif
783 aurora_receive(bp,chip);
785 else if (ack == (chip_id | GSVR_IT_REXC)){
786 #ifdef AURORA_INTMSG
787 printk("RXC ACK\n");
788 #endif
789 aurora_receive_exc(bp,chip);
791 else
792 #ifdef AURORA_INTNORM
793 printk("aurora%d-%d: Bad receive ack 0x%02x.\n",
794 board_No(bp), chip, ack)
795 #endif
798 } else if (status & SRSR_TEXT) {
799 ack = bp->r3->r[bp->ACK_TINT];
800 if (ack == (chip_id | GSVR_IT_TX)){
801 #ifdef AURORA_INTMSG
802 printk("TX ACK\n");
803 #endif
804 aurora_transmit(bp,chip);
806 else{
807 #ifdef AURORA_INTNORM
808 printk("aurora%d-%d: Bad transmit ack 0x%02x.\n",
809 board_No(bp), chip, ack);
810 #endif
813 } else if (status & SRSR_MEXT) {
814 ack = bp->r3->r[bp->ACK_MINT];
815 if (ack == (chip_id | GSVR_IT_MDM)){
816 #ifdef AURORA_INTMSG
817 printk("MDM ACK\n");
818 #endif
819 aurora_check_modem(bp,chip);
821 else
822 #ifdef AURORA_INTNORM
823 printk("aurora%d-%d: Bad modem ack 0x%02x.\n",
824 board_No(bp), chip, ack)
825 #endif
829 bp->r[chip]->r[CD180_EOSRR]=0;
836 #ifdef AURORA_INT_DEBUG
837 static void aurora_timer (unsigned long ignored);
839 static struct timer_list
840 aurora_poll_timer = { NULL, NULL, 0, 0, aurora_timer };
842 static void
843 aurora_timer (unsigned long ignored)
845 unsigned long flags;
846 int i;
848 save_flags(flags); cli();
850 printk("SRSR: %02x,%02x - ",aurora_board[0].r[0]->r[CD180_SRSR],aurora_board[0].r[1]->r[CD180_SRSR]);
851 for(i=0;i<4;i++){
852 udelay(1);
853 printk("%02x ",aurora_board[0].r3->r[i]);
855 printk("\n");
857 aurora_poll_timer.expires = jiffies + 300;
858 add_timer (&aurora_poll_timer);
860 restore_flags(flags);
862 #endif
865 * Routines for open & close processing.
868 /* Called with disabled interrupts */
869 extern inline int aurora_setup_board(struct Aurora_board * bp)
871 int error;
873 #ifdef AURORA_ALLIRQ
874 int i;
875 for(i=0;i<AURORA_ALLIRQ;i++){
876 error = request_irq(allirq[i]|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp);
877 if (error){
878 printk(KERN_ERR "IRQ%d request error %d\n",allirq[i],error);
881 #else
882 error = request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp);
883 if (error){
884 printk(KERN_ERR "IRQ request error %d\n",error);
885 return error;
887 #endif
888 /* Board reset */
889 bp->r0->r=0;
890 udelay(1);
891 if(bp->flags&AURORA_BOARD_TYPE_2){
892 /* unknown yet */
893 } else {
894 bp->r0->r=AURORA_CFG_ENABLE_IO|AURORA_CFG_ENABLE_IRQ|(((bp->irq)&0x0f)>>2);
896 udelay(10000);
898 if (aurora_init_CD180(bp,0))error=1;error=0;
899 if (aurora_init_CD180(bp,1))error++;
900 if (error==AURORA_NCD180) {
901 printk(KERN_ERR "Both chips failed initialisation.\n");
902 return -EIO;
905 #ifdef AURORA_INT_DEBUG
906 aurora_poll_timer.expires=jiffies+1;
907 add_timer(&aurora_poll_timer);
908 #endif
909 #ifdef AURORA_DEBUG
910 printk("aurora_setup_board: end\n");
911 #endif
912 return 0;
915 /* Called with disabled interrupts */
916 extern inline void aurora_shutdown_board(struct Aurora_board *bp)
918 int i;
920 #ifdef AURORA_DEBUG
921 printk("aurora_shutdown_board: start\n");
922 #endif
924 #ifdef AURORA_INT_DEBUG
925 del_timer(&aurora_poll_timer);
926 #endif
928 #ifdef AURORA_ALLIRQ
929 for(i=0;i<AURORA_ALLIRQ;i++){
930 free_irq(allirq[i]|0x30, bp);
931 /* IRQ_to_board[allirq[i]&0xf] = NULL;*/
933 #else
934 free_irq(bp->irq|0x30, bp);
935 /* IRQ_to_board[bp->irq&0xf] = NULL;*/
936 #endif
937 /* Drop all DTR's */
938 for(i=0;i<16;i++){
939 bp->r[i>>3]->r[CD180_CAR]=i&7;
940 udelay(1);
941 bp->r[i>>3]->r[CD180_MSVR]=0;
942 udelay(1);
944 /* Board shutdown */
945 bp->r0->r=0;
947 #ifdef AURORA_DEBUG
948 printk("aurora_shutdown_board: end\n");
949 #endif
953 * Setting up port characteristics.
954 * Must be called with disabled interrupts
956 static void aurora_change_speed(struct Aurora_board *bp, struct Aurora_port *port)
958 struct tty_struct *tty;
959 unsigned long baud;
960 long tmp;
961 unsigned char cor1 = 0, cor3 = 0;
962 unsigned char mcor1 = 0, mcor2 = 0,chip;
964 #ifdef AURORA_DEBUG
965 printk("aurora_change_speed: start\n");
966 #endif
967 if (!(tty = port->tty) || !tty->termios)
968 return;
970 chip=AURORA_CD180(port_No(port));
972 port->SRER = 0;
973 port->COR2 = 0;
974 port->MSVR = MSVR_RTS|MSVR_DTR;
976 baud = C_BAUD(tty);
978 if (baud & CBAUDEX) {
979 baud &= ~CBAUDEX;
980 if (baud < 1 || baud > 2)
981 port->tty->termios->c_cflag &= ~CBAUDEX;
982 else
983 baud += 15;
985 if (baud == 15) {
986 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
987 baud ++;
988 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
989 baud += 2;
992 /* Select port on the board */
993 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
994 udelay(1);
996 if (!baud_table[baud]) {
997 /* Drop DTR & exit */
998 port->MSVR &= ~(bp->DTR|bp->RTS);
999 bp->r[chip]->r[CD180_MSVR]=port->MSVR;
1000 return;
1001 } else {
1002 /* Set DTR on */
1003 port->MSVR |= bp->DTR;
1004 bp->r[chip]->r[CD180_MSVR]=port->MSVR;
1008 * Now we must calculate some speed depended things
1011 /* Set baud rate for port */
1012 tmp = (((bp->oscfreq + baud_table[baud]/2) / baud_table[baud] +
1013 CD180_TPC/2) / CD180_TPC);
1015 /* tmp = (bp->oscfreq/7)/baud_table[baud];
1016 if((tmp%10)>4)tmp=tmp/10+1;else tmp=tmp/10;*/
1017 /* printk("Prescaler period: %d\n",tmp);*/
1019 bp->r[chip]->r[CD180_RBPRH]=(tmp >> 8) & 0xff;
1020 bp->r[chip]->r[CD180_TBPRH]=(tmp >> 8) & 0xff;
1021 bp->r[chip]->r[CD180_RBPRL]=tmp & 0xff;
1022 bp->r[chip]->r[CD180_TBPRL]=tmp & 0xff;
1024 baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */
1026 /* Two timer ticks seems enough to wakeup something like SLIP driver */
1027 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
1028 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
1029 SERIAL_XMIT_SIZE - 1 : tmp);
1031 /* Receiver timeout will be transmission time for 1.5 chars */
1032 tmp = (AURORA_TPS + AURORA_TPS/2 + baud/2) / baud;
1033 tmp = (tmp > 0xff) ? 0xff : tmp;
1034 bp->r[chip]->r[CD180_RTPR]=tmp;
1036 switch (C_CSIZE(tty)) {
1037 case CS5:
1038 cor1 |= COR1_5BITS;
1039 break;
1040 case CS6:
1041 cor1 |= COR1_6BITS;
1042 break;
1043 case CS7:
1044 cor1 |= COR1_7BITS;
1045 break;
1046 case CS8:
1047 cor1 |= COR1_8BITS;
1048 break;
1051 if (C_CSTOPB(tty))
1052 cor1 |= COR1_2SB;
1054 cor1 |= COR1_IGNORE;
1055 if (C_PARENB(tty)) {
1056 cor1 |= COR1_NORMPAR;
1057 if (C_PARODD(tty))
1058 cor1 |= COR1_ODDP;
1059 if (I_INPCK(tty))
1060 cor1 &= ~COR1_IGNORE;
1062 /* Set marking of some errors */
1063 port->mark_mask = RCSR_OE | RCSR_TOUT;
1064 if (I_INPCK(tty))
1065 port->mark_mask |= RCSR_FE | RCSR_PE;
1066 if (I_BRKINT(tty) || I_PARMRK(tty))
1067 port->mark_mask |= RCSR_BREAK;
1068 if (I_IGNPAR(tty))
1069 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
1070 if (I_IGNBRK(tty)) {
1071 port->mark_mask &= ~RCSR_BREAK;
1072 if (I_IGNPAR(tty))
1073 /* Real raw mode. Ignore all */
1074 port->mark_mask &= ~RCSR_OE;
1076 /* Enable Hardware Flow Control */
1077 if (C_CRTSCTS(tty)) {
1078 /*#ifdef AURORA_BRAIN_DAMAGED_CTS
1079 port->SRER |= SRER_DSR | SRER_CTS;
1080 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
1081 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
1082 tty->hw_stopped = !(aurora_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
1083 #else*/
1084 port->COR2 |= COR2_CTSAE;
1085 /*#endif*/
1086 if (bp->flags&AURORA_BOARD_DTR_FLOW_OK) {
1087 mcor1 |= AURORA_RXTH;
1090 /* Enable Software Flow Control. FIXME: I'm not sure about this */
1091 /* Some people reported that it works, but I still doubt */
1092 if (I_IXON(tty)) {
1093 port->COR2 |= COR2_TXIBE;
1094 cor3 |= (COR3_FCT | COR3_SCDE);
1095 if (I_IXANY(tty))
1096 port->COR2 |= COR2_IXM;
1097 bp->r[chip]->r[CD180_SCHR1]=START_CHAR(tty);
1098 bp->r[chip]->r[CD180_SCHR2]=STOP_CHAR(tty);
1099 bp->r[chip]->r[CD180_SCHR3]=START_CHAR(tty);
1100 bp->r[chip]->r[CD180_SCHR4]=STOP_CHAR(tty);
1102 if (!C_CLOCAL(tty)) {
1103 /* Enable CD check */
1104 port->SRER |= SRER_CD;
1105 mcor1 |= MCOR1_CDZD;
1106 mcor2 |= MCOR2_CDOD;
1109 if (C_CREAD(tty))
1110 /* Enable receiver */
1111 port->SRER |= SRER_RXD;
1113 /* Set input FIFO size (1-8 bytes) */
1114 cor3 |= AURORA_RXFIFO;
1115 /* Setting up CD180 channel registers */
1116 bp->r[chip]->r[CD180_COR1]=cor1;
1117 bp->r[chip]->r[CD180_COR2]=port->COR2;
1118 bp->r[chip]->r[CD180_COR3]=cor3;
1119 /* Make CD180 know about registers change */
1120 aurora_wait_CCR(bp->r[chip]);
1121 bp->r[chip]->r[CD180_CCR]=CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3;
1122 /* Setting up modem option registers */
1123 bp->r[chip]->r[CD180_MCOR1]=mcor1;
1124 bp->r[chip]->r[CD180_MCOR2]=mcor2;
1125 /* Enable CD180 transmitter & receiver */
1126 aurora_wait_CCR(bp->r[chip]);
1127 bp->r[chip]->r[CD180_CCR]=CCR_TXEN | CCR_RXEN;
1128 /* Enable interrupts */
1129 bp->r[chip]->r[CD180_SRER]=port->SRER;
1130 /* And finally set RTS on */
1131 bp->r[chip]->r[CD180_MSVR]=port->MSVR;
1132 #ifdef AURORA_DEBUG
1133 printk("aurora_change_speed: end\n");
1134 #endif
1137 /* Must be called with interrupts enabled */
1138 static int aurora_setup_port(struct Aurora_board *bp, struct Aurora_port *port)
1140 unsigned long flags;
1142 #ifdef AURORA_DEBUG
1143 printk("aurora_setup_port: start %d\n",port_No(port));
1144 #endif
1145 if (port->flags & ASYNC_INITIALIZED)
1146 return 0;
1148 if (!port->xmit_buf) {
1149 /* We may sleep in get_free_page() */
1150 unsigned long tmp;
1152 if (!(tmp = get_free_page(GFP_KERNEL)))
1153 return -ENOMEM;
1155 if (port->xmit_buf) {
1156 free_page(tmp);
1157 return -ERESTARTSYS;
1159 port->xmit_buf = (unsigned char *) tmp;
1162 save_flags(flags); cli();
1164 if (port->tty)
1165 clear_bit(TTY_IO_ERROR, &port->tty->flags);
1167 #ifdef MODULE
1168 if (port->count == 1) {
1169 MOD_INC_USE_COUNT;
1170 if((++bp->count)==1)
1171 bp->flags|=AURORA_BOARD_ACTIVE;
1173 #endif
1175 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1176 aurora_change_speed(bp, port);
1177 port->flags |= ASYNC_INITIALIZED;
1179 restore_flags(flags);
1180 #ifdef AURORA_DEBUG
1181 printk("aurora_setup_port: end\n");
1182 #endif
1183 return 0;
1186 /* Must be called with interrupts disabled */
1187 static void aurora_shutdown_port(struct Aurora_board *bp, struct Aurora_port *port)
1189 struct tty_struct *tty;
1190 unsigned char chip;
1192 #ifdef AURORA_DEBUG
1193 printk("aurora_shutdown_port: start\n");
1194 #endif
1195 if (!(port->flags & ASYNC_INITIALIZED))
1196 return;
1198 chip=AURORA_CD180(port_No(port));
1200 #ifdef AURORA_REPORT_OVERRUN
1201 printk("aurora%d: port %d: Total %ld overruns were detected.\n",
1202 board_No(bp), port_No(port), port->overrun);
1203 #endif
1204 #ifdef AURORA_REPORT_FIFO
1206 int i;
1208 printk("aurora%d: port %d: FIFO hits [ ",
1209 board_No(bp), port_No(port));
1210 for (i = 0; i < 10; i++) {
1211 printk("%ld ", port->hits[i]);
1213 printk("].\n");
1215 #endif
1216 if (port->xmit_buf) {
1217 free_page((unsigned long) port->xmit_buf);
1218 port->xmit_buf = NULL;
1221 if (!(tty = port->tty) || C_HUPCL(tty)) {
1222 /* Drop DTR */
1223 port->MSVR &= ~(bp->DTR|bp->RTS);
1224 bp->r[chip]->r[CD180_MSVR]=port->MSVR;
1227 /* Select port */
1228 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
1229 udelay(1);
1230 /* Reset port */
1231 aurora_wait_CCR(bp->r[chip]);
1232 bp->r[chip]->r[CD180_CCR]=CCR_SOFTRESET;
1233 /* Disable all interrupts from this port */
1234 port->SRER = 0;
1235 bp->r[chip]->r[CD180_SRER]=port->SRER;
1237 if (tty)
1238 set_bit(TTY_IO_ERROR, &tty->flags);
1239 port->flags &= ~ASYNC_INITIALIZED;
1241 #ifdef MODULE
1242 if (--bp->count < 0) {
1243 printk(KERN_DEBUG "aurora%d: aurora_shutdown_port: bad board count: %d\n",
1244 board_No(bp), bp->count);
1245 bp->count = 0;
1248 MOD_DEC_USE_COUNT;
1249 if (!bp->count)
1250 bp->flags&=~AURORA_BOARD_ACTIVE;
1251 #endif
1253 #ifdef AURORA_DEBUG
1254 printk("aurora_shutdown_port: end\n");
1255 #endif
1259 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1260 struct Aurora_port *port)
1262 DECLARE_WAITQUEUE(wait, current);
1263 struct Aurora_board *bp = port_Board(port);
1264 int retval;
1265 int do_clocal = 0;
1266 int CD;
1267 unsigned char chip;
1269 #ifdef AURORA_DEBUG
1270 printk("block_til_ready: start\n");
1271 #endif
1272 chip=AURORA_CD180(port_No(port));
1275 * If the device is in the middle of being closed, then block
1276 * until it's done, and then try again.
1278 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
1279 interruptible_sleep_on(&port->close_wait);
1280 if (port->flags & ASYNC_HUP_NOTIFY)
1281 return -EAGAIN;
1282 else
1283 return -ERESTARTSYS;
1287 * If non-blocking mode is set, or the port is not enabled,
1288 * then make the check up front and then exit.
1290 if ((filp->f_flags & O_NONBLOCK) ||
1291 (tty->flags & (1 << TTY_IO_ERROR))) {
1292 if (port->flags & ASYNC_CALLOUT_ACTIVE)
1293 return -EBUSY;
1294 port->flags |= ASYNC_NORMAL_ACTIVE;
1295 return 0;
1298 if (port->flags & ASYNC_CALLOUT_ACTIVE) {
1299 if (port->normal_termios.c_cflag & CLOCAL)
1300 do_clocal = 1;
1301 } else {
1302 if (C_CLOCAL(tty))
1303 do_clocal = 1;
1307 * Block waiting for the carrier detect and the line to become
1308 * free (i.e., not in use by the callout). While we are in
1309 * this loop, info->count is dropped by one, so that
1310 * rs_close() knows when to free things. We restore it upon
1311 * exit, either normal or abnormal.
1313 retval = 0;
1314 add_wait_queue(&port->open_wait, &wait);
1315 cli();
1316 if (!tty_hung_up_p(filp))
1317 port->count--;
1318 sti();
1319 port->blocked_open++;
1320 while (1) {
1321 cli();
1322 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
1323 udelay(1);
1324 CD = bp->r[chip]->r[CD180_MSVR] & MSVR_CD;
1325 if (!(port->flags & ASYNC_CALLOUT_ACTIVE)) {
1326 port->MSVR=bp->RTS;
1327 bp->r[chip]->r[CD180_MSVR]=port->MSVR;/* auto drops DTR */
1329 sti();
1330 set_current_state(TASK_INTERRUPTIBLE);
1331 if (tty_hung_up_p(filp) ||
1332 !(port->flags & ASYNC_INITIALIZED)) {
1333 if (port->flags & ASYNC_HUP_NOTIFY)
1334 retval = -EAGAIN;
1335 else
1336 retval = -ERESTARTSYS;
1337 break;
1339 if (/*!(port->flags & ASYNC_CALLOUT_ACTIVE) &&*/
1340 !(port->flags & ASYNC_CLOSING) &&
1341 (do_clocal || CD))
1342 break;
1343 if (signal_pending(current)) {
1344 retval = -ERESTARTSYS;
1345 break;
1347 schedule();
1349 current->state = TASK_RUNNING;
1350 remove_wait_queue(&port->open_wait, &wait);
1351 if (!tty_hung_up_p(filp))
1352 port->count++;
1353 port->blocked_open--;
1354 if (retval)
1355 return retval;
1357 port->flags |= ASYNC_NORMAL_ACTIVE;
1358 #ifdef AURORA_DEBUG
1359 printk("block_til_ready: end\n");
1360 #endif
1361 return 0;
1364 static int aurora_open(struct tty_struct * tty, struct file * filp)
1366 int board;
1367 int error;
1368 struct Aurora_port * port;
1369 struct Aurora_board * bp;
1370 unsigned long flags;
1372 #ifdef AURORA_DEBUG
1373 printk("aurora_open: start\n");
1374 #endif
1376 board = AURORA_BOARD(MINOR(tty->device));
1377 if (board > AURORA_NBOARD || !(aurora_board[board].flags & AURORA_BOARD_PRESENT)){
1378 #ifdef AURORA_DEBUG
1379 printk("aurora_open: error board %d present %d\n",board,aurora_board[board].flags &AURORA_BOARD_PRESENT);
1380 #endif
1381 return -ENODEV;
1384 bp = &aurora_board[board];
1385 port = aurora_port + board * AURORA_NPORT * AURORA_NCD180 + AURORA_PORT(MINOR(tty->device));
1386 if (aurora_paranoia_check(port, tty->device, "aurora_open")){
1387 #ifdef AURORA_DEBUG
1388 printk("aurora_open: error paranoia check\n");
1389 #endif
1390 return -ENODEV;
1393 port->count++;
1394 tty->driver_data = port;
1395 port->tty = tty;
1397 if ((error = aurora_setup_port(bp, port))) {
1398 #ifdef AURORA_DEBUG
1399 printk("aurora_open: error aurora_setup_port ret %d\n",error);
1400 #endif
1401 return error;
1404 if ((error = block_til_ready(tty, filp, port))){
1405 #ifdef AURORA_DEBUG
1406 printk("aurora_open: error block_til_ready ret %d\n",error);
1407 #endif
1408 return error;
1411 if ((port->count == 1) && (port->flags & ASYNC_SPLIT_TERMIOS)) {
1412 *tty->termios = port->normal_termios;
1413 save_flags(flags); cli();
1414 aurora_change_speed(bp, port);
1415 restore_flags(flags);
1418 port->session = current->session;
1419 port->pgrp = current->pgrp;
1420 #ifdef AURORA_DEBUG
1421 printk("aurora_open: end\n");
1422 #endif
1423 return 0;
1426 static void aurora_close(struct tty_struct * tty, struct file * filp)
1428 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1429 struct Aurora_board *bp;
1430 unsigned long flags;
1431 unsigned long timeout;
1432 unsigned char chip;
1434 #ifdef AURORA_DEBUG
1435 printk("aurora_close: start\n");
1436 #endif
1438 if (!port || aurora_paranoia_check(port, tty->device, "close"))
1439 return;
1441 chip=AURORA_CD180(port_No(port));
1443 save_flags(flags); cli();
1444 if (tty_hung_up_p(filp)) {
1445 restore_flags(flags);
1446 return;
1449 bp = port_Board(port);
1450 if ((tty->count == 1) && (port->count != 1)) {
1451 printk(KERN_DEBUG "aurora%d: aurora_close: bad port count; tty->count is 1, port count is %d\n",
1452 board_No(bp), port->count);
1453 port->count = 1;
1455 if (--port->count < 0) {
1456 printk(KERN_DEBUG "aurora%d: aurora_close: bad port count for tty%d: %d\n",
1457 board_No(bp), port_No(port), port->count);
1458 port->count = 0;
1460 if (port->count) {
1461 restore_flags(flags);
1462 return;
1464 port->flags |= ASYNC_CLOSING;
1466 * Save the termios structure, since this port may have
1467 * separate termios for callout and dialin.
1469 if (port->flags & ASYNC_NORMAL_ACTIVE)
1470 port->normal_termios = *tty->termios;
1471 /* if (port->flags & ASYNC_CALLOUT_ACTIVE)
1472 port->callout_termios = *tty->termios;*/
1474 * Now we wait for the transmit buffer to clear; and we notify
1475 * the line discipline to only process XON/XOFF characters.
1477 tty->closing = 1;
1478 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE){
1479 #ifdef AURORA_DEBUG
1480 printk("aurora_close: waiting to flush...\n");
1481 #endif
1482 tty_wait_until_sent(tty, port->closing_wait);
1485 * At this point we stop accepting input. To do this, we
1486 * disable the receive line status interrupts, and tell the
1487 * interrupt driver to stop checking the data ready bit in the
1488 * line status register.
1490 port->SRER &= ~SRER_RXD;
1491 if (port->flags & ASYNC_INITIALIZED) {
1492 port->SRER &= ~SRER_TXRDY;
1493 port->SRER |= SRER_TXEMPTY;
1494 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
1495 udelay(1);
1496 bp->r[chip]->r[CD180_SRER]=port->SRER;
1498 * Before we drop DTR, make sure the UART transmitter
1499 * has completely drained; this is especially
1500 * important if there is a transmit FIFO!
1502 timeout = jiffies+HZ;
1503 while(port->SRER & SRER_TXEMPTY) {
1504 current->state = TASK_INTERRUPTIBLE;
1505 schedule_timeout(port->timeout);
1506 if (time_after(jiffies, timeout))
1507 break;
1510 #ifdef AURORA_DEBUG
1511 printk("aurora_close: shutdown_port\n");
1512 #endif
1513 aurora_shutdown_port(bp, port);
1514 if (tty->driver.flush_buffer)
1515 tty->driver.flush_buffer(tty);
1516 if (tty->ldisc.flush_buffer)
1517 tty->ldisc.flush_buffer(tty);
1518 tty->closing = 0;
1519 port->event = 0;
1520 port->tty = 0;
1521 if (port->blocked_open) {
1522 if (port->close_delay) {
1523 current->state = TASK_INTERRUPTIBLE;
1524 schedule_timeout(port->close_delay);
1526 wake_up_interruptible(&port->open_wait);
1528 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
1529 ASYNC_CLOSING);
1530 wake_up_interruptible(&port->close_wait);
1531 restore_flags(flags);
1532 #ifdef AURORA_DEBUG
1533 printk("aurora_close: end\n");
1534 #endif
1537 static int aurora_write(struct tty_struct * tty, int from_user,
1538 const unsigned char *buf, int count)
1540 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
1541 struct Aurora_board *bp;
1542 int c, total = 0;
1543 unsigned long flags;
1544 unsigned char chip;
1546 #ifdef AURORA_DEBUG
1547 printk("aurora_write: start %d\n",count);
1548 #endif
1549 if (aurora_paranoia_check(port, tty->device, "aurora_write"))
1550 return 0;
1552 chip=AURORA_CD180(port_No(port));
1554 bp = port_Board(port);
1556 if (!tty || !port->xmit_buf || !tmp_buf)
1557 return 0;
1559 if (from_user)
1560 down(&tmp_buf_sem);
1562 save_flags(flags);
1563 while (1) {
1564 cli();
1565 c = MIN(count, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1566 SERIAL_XMIT_SIZE - port->xmit_head));
1567 if (c <= 0)
1568 break;
1570 if (from_user) {
1571 copy_from_user(tmp_buf, buf, c);
1572 c = MIN(c, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1573 SERIAL_XMIT_SIZE - port->xmit_head));
1574 memcpy(port->xmit_buf + port->xmit_head, tmp_buf, c);
1575 } else
1576 memcpy(port->xmit_buf + port->xmit_head, buf, c);
1577 port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1578 port->xmit_cnt += c;
1579 restore_flags(flags);
1580 buf += c;
1581 count -= c;
1582 total += c;
1584 if (from_user)
1585 up(&tmp_buf_sem);
1586 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1587 !(port->SRER & SRER_TXRDY)) {
1588 port->SRER |= SRER_TXRDY;
1589 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
1590 udelay(1);
1591 bp->r[chip]->r[CD180_SRER]=port->SRER;
1593 restore_flags(flags);
1594 #ifdef AURORA_DEBUG
1595 printk("aurora_write: end %d\n",total);
1596 #endif
1597 return total;
1600 static void aurora_put_char(struct tty_struct * tty, unsigned char ch)
1602 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
1603 unsigned long flags;
1605 #ifdef AURORA_DEBUG
1606 printk("aurora_put_char: start %c\n",ch);
1607 #endif
1608 if (aurora_paranoia_check(port, tty->device, "aurora_put_char"))
1609 return;
1611 if (!tty || !port->xmit_buf)
1612 return;
1614 save_flags(flags); cli();
1616 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
1617 restore_flags(flags);
1618 return;
1621 port->xmit_buf[port->xmit_head++] = ch;
1622 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1623 port->xmit_cnt++;
1624 restore_flags(flags);
1625 #ifdef AURORA_DEBUG
1626 printk("aurora_put_char: end\n");
1627 #endif
1630 static void aurora_flush_chars(struct tty_struct * tty)
1632 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
1633 unsigned long flags;
1634 unsigned char chip;
1636 /*#ifdef AURORA_DEBUG
1637 printk("aurora_flush_chars: start\n");
1638 #endif*/
1639 if (aurora_paranoia_check(port, tty->device, "aurora_flush_chars"))
1640 return;
1642 chip=AURORA_CD180(port_No(port));
1644 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1645 !port->xmit_buf)
1646 return;
1648 save_flags(flags); cli();
1649 port->SRER |= SRER_TXRDY;
1650 port_Board(port)->r[chip]->r[CD180_CAR]=port_No(port)&7;
1651 udelay(1);
1652 port_Board(port)->r[chip]->r[CD180_SRER]=port->SRER;
1653 restore_flags(flags);
1654 /*#ifdef AURORA_DEBUG
1655 printk("aurora_flush_chars: end\n");
1656 #endif*/
1659 static int aurora_write_room(struct tty_struct * tty)
1661 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
1662 int ret;
1664 #ifdef AURORA_DEBUG
1665 printk("aurora_write_room: start\n");
1666 #endif
1667 if (aurora_paranoia_check(port, tty->device, "aurora_write_room"))
1668 return 0;
1670 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1671 if (ret < 0)
1672 ret = 0;
1673 #ifdef AURORA_DEBUG
1674 printk("aurora_write_room: end\n");
1675 #endif
1676 return ret;
1679 static int aurora_chars_in_buffer(struct tty_struct *tty)
1681 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
1683 if (aurora_paranoia_check(port, tty->device, "aurora_chars_in_buffer"))
1684 return 0;
1686 return port->xmit_cnt;
1689 static void aurora_flush_buffer(struct tty_struct *tty)
1691 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
1692 unsigned long flags;
1694 #ifdef AURORA_DEBUG
1695 printk("aurora_flush_buffer: start\n");
1696 #endif
1697 if (aurora_paranoia_check(port, tty->device, "aurora_flush_buffer"))
1698 return;
1700 save_flags(flags); cli();
1701 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1702 restore_flags(flags);
1704 wake_up_interruptible(&tty->write_wait);
1705 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1706 tty->ldisc.write_wakeup)
1707 (tty->ldisc.write_wakeup)(tty);
1708 #ifdef AURORA_DEBUG
1709 printk("aurora_flush_buffer: end\n");
1710 #endif
1713 static int aurora_get_modem_info(struct Aurora_port * port, unsigned int *value)
1715 struct Aurora_board * bp;
1716 unsigned char status,chip;
1717 unsigned int result;
1718 unsigned long flags;
1720 #ifdef AURORA_DEBUG
1721 printk("aurora_get_modem_info: start\n");
1722 #endif
1723 chip=AURORA_CD180(port_No(port));
1725 bp = port_Board(port);
1726 save_flags(flags); cli();
1727 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
1728 udelay(1);
1729 status = bp->r[chip]->r[CD180_MSVR];
1730 result = 0/*bp->r[chip]->r[AURORA_RI] & (1u << port_No(port)) ? 0 : TIOCM_RNG*/;
1731 restore_flags(flags);
1732 result |= ((status & bp->RTS) ? TIOCM_RTS : 0)
1733 | ((status & bp->DTR) ? TIOCM_DTR : 0)
1734 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1735 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1736 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1737 put_user(result,(unsigned long *) value);
1738 #ifdef AURORA_DEBUG
1739 printk("aurora_get_modem_info: end\n");
1740 #endif
1741 return 0;
1744 static int aurora_set_modem_info(struct Aurora_port * port, unsigned int cmd,
1745 unsigned int *value)
1747 int error;
1748 unsigned int arg;
1749 unsigned long flags;
1750 struct Aurora_board *bp = port_Board(port);
1751 unsigned char chip;
1753 #ifdef AURORA_DEBUG
1754 printk("aurora_set_modem_info: start\n");
1755 #endif
1756 error = get_user(arg, value);
1757 if (error)
1758 return error;
1759 chip=AURORA_CD180(port_No(port));
1760 switch (cmd) {
1761 case TIOCMBIS:
1762 if (arg & TIOCM_RTS)
1763 port->MSVR |= bp->RTS;
1764 if (arg & TIOCM_DTR)
1765 port->MSVR |= bp->DTR;
1766 break;
1767 case TIOCMBIC:
1768 if (arg & TIOCM_RTS)
1769 port->MSVR &= ~bp->RTS;
1770 if (arg & TIOCM_DTR)
1771 port->MSVR &= ~bp->DTR;
1772 break;
1773 case TIOCMSET:
1774 port->MSVR = (arg & TIOCM_RTS) ? (port->MSVR | bp->RTS) :
1775 (port->MSVR & ~bp->RTS);
1776 port->MSVR = (arg & TIOCM_DTR) ? (port->MSVR | bp->RTS) :
1777 (port->MSVR & ~bp->RTS);
1778 break;
1779 default:
1780 return -EINVAL;
1782 save_flags(flags); cli();
1783 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
1784 udelay(1);
1785 bp->r[chip]->r[CD180_MSVR]=port->MSVR;
1786 restore_flags(flags);
1787 #ifdef AURORA_DEBUG
1788 printk("aurora_set_modem_info: end\n");
1789 #endif
1790 return 0;
1793 extern inline void aurora_send_break(struct Aurora_port * port, unsigned long length)
1795 struct Aurora_board *bp = port_Board(port);
1796 unsigned long flags;
1797 unsigned char chip;
1799 #ifdef AURORA_DEBUG
1800 printk("aurora_send_break: start\n");
1801 #endif
1802 chip=AURORA_CD180(port_No(port));
1804 save_flags(flags); cli();
1805 port->break_length = AURORA_TPS / HZ * length;
1806 port->COR2 |= COR2_ETC;
1807 port->SRER |= SRER_TXRDY;
1808 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
1809 udelay(1);
1810 bp->r[chip]->r[CD180_COR2]=port->COR2;
1811 bp->r[chip]->r[CD180_SRER]=port->SRER;
1812 aurora_wait_CCR(bp->r[chip]);
1813 bp->r[chip]->r[CD180_CCR]=CCR_CORCHG2;
1814 aurora_wait_CCR(bp->r[chip]);
1815 restore_flags(flags);
1816 #ifdef AURORA_DEBUG
1817 printk("aurora_send_break: end\n");
1818 #endif
1821 extern inline int aurora_set_serial_info(struct Aurora_port * port,
1822 struct serial_struct * newinfo)
1824 struct serial_struct tmp;
1825 struct Aurora_board *bp = port_Board(port);
1826 int change_speed;
1827 unsigned long flags;
1828 int error;
1830 #ifdef AURORA_DEBUG
1831 printk("aurora_set_serial_info: start\n");
1832 #endif
1833 error = verify_area(VERIFY_READ, (void *) newinfo, sizeof(tmp));
1834 if (error)
1835 return error;
1836 copy_from_user(&tmp, newinfo, sizeof(tmp));
1838 #if 0
1839 if ((tmp.irq != bp->irq) ||
1840 (tmp.port != bp->base) ||
1841 (tmp.type != PORT_CIRRUS) ||
1842 (tmp.baud_base != (bp->oscfreq + CD180_TPC/2) / CD180_TPC) ||
1843 (tmp.custom_divisor != 0) ||
1844 (tmp.xmit_fifo_size != CD180_NFIFO) ||
1845 (tmp.flags & ~AURORA_LEGAL_FLAGS))
1846 return -EINVAL;
1847 #endif
1849 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1850 (tmp.flags & ASYNC_SPD_MASK));
1852 if (!suser()) {
1853 if ((tmp.close_delay != port->close_delay) ||
1854 (tmp.closing_wait != port->closing_wait) ||
1855 ((tmp.flags & ~ASYNC_USR_MASK) !=
1856 (port->flags & ~ASYNC_USR_MASK)))
1857 return -EPERM;
1858 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1859 (tmp.flags & ASYNC_USR_MASK));
1860 } else {
1861 port->flags = ((port->flags & ~ASYNC_FLAGS) |
1862 (tmp.flags & ASYNC_FLAGS));
1863 port->close_delay = tmp.close_delay;
1864 port->closing_wait = tmp.closing_wait;
1866 if (change_speed) {
1867 save_flags(flags); cli();
1868 aurora_change_speed(bp, port);
1869 restore_flags(flags);
1871 #ifdef AURORA_DEBUG
1872 printk("aurora_set_serial_info: end\n");
1873 #endif
1874 return 0;
1877 extern inline int aurora_get_serial_info(struct Aurora_port * port,
1878 struct serial_struct * retinfo)
1880 struct serial_struct tmp;
1881 struct Aurora_board *bp = port_Board(port);
1882 int error;
1884 #ifdef AURORA_DEBUG
1885 printk("aurora_get_serial_info: start\n");
1886 #endif
1887 error = verify_area(VERIFY_WRITE, (void *) retinfo, sizeof(tmp));
1888 if (error)
1889 return error;
1891 memset(&tmp, 0, sizeof(tmp));
1892 tmp.type = PORT_CIRRUS;
1893 tmp.line = port - aurora_port;
1894 tmp.port = 0;
1895 tmp.irq = bp->irq;
1896 tmp.flags = port->flags;
1897 tmp.baud_base = (bp->oscfreq + CD180_TPC/2) / CD180_TPC;
1898 tmp.close_delay = port->close_delay * HZ/100;
1899 tmp.closing_wait = port->closing_wait * HZ/100;
1900 tmp.xmit_fifo_size = CD180_NFIFO;
1901 copy_to_user(retinfo, &tmp, sizeof(tmp));
1902 #ifdef AURORA_DEBUG
1903 printk("aurora_get_serial_info: end\n");
1904 #endif
1905 return 0;
1908 static int aurora_ioctl(struct tty_struct * tty, struct file * filp,
1909 unsigned int cmd, unsigned long arg)
1912 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
1913 int error;
1914 int retval;
1916 #ifdef AURORA_DEBUG
1917 printk("aurora_ioctl: start\n");
1918 #endif
1919 if (aurora_paranoia_check(port, tty->device, "aurora_ioctl"))
1920 return -ENODEV;
1922 switch (cmd) {
1923 case TCSBRK: /* SVID version: non-zero arg --> no break */
1924 retval = tty_check_change(tty);
1925 if (retval)
1926 return retval;
1927 tty_wait_until_sent(tty, 0);
1928 if (!arg)
1929 aurora_send_break(port, HZ/4); /* 1/4 second */
1930 return 0;
1931 case TCSBRKP: /* support for POSIX tcsendbreak() */
1932 retval = tty_check_change(tty);
1933 if (retval)
1934 return retval;
1935 tty_wait_until_sent(tty, 0);
1936 aurora_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1937 return 0;
1938 case TIOCGSOFTCAR:
1939 error = verify_area(VERIFY_WRITE, (void *) arg, sizeof(long));
1940 if (error)
1941 return error;
1942 put_user(C_CLOCAL(tty) ? 1 : 0,
1943 (unsigned long *) arg);
1944 return 0;
1945 case TIOCSSOFTCAR:
1946 retval = get_user(arg,(unsigned long *) arg);
1947 if (retval)
1948 return retval;
1949 tty->termios->c_cflag =
1950 ((tty->termios->c_cflag & ~CLOCAL) |
1951 (arg ? CLOCAL : 0));
1952 return 0;
1953 case TIOCMGET:
1954 error = verify_area(VERIFY_WRITE, (void *) arg,
1955 sizeof(unsigned int));
1956 if (error)
1957 return error;
1958 return aurora_get_modem_info(port, (unsigned int *) arg);
1959 case TIOCMBIS:
1960 case TIOCMBIC:
1961 case TIOCMSET:
1962 return aurora_set_modem_info(port, cmd, (unsigned int *) arg);
1963 case TIOCGSERIAL:
1964 return aurora_get_serial_info(port, (struct serial_struct *) arg);
1965 case TIOCSSERIAL:
1966 return aurora_set_serial_info(port, (struct serial_struct *) arg);
1967 default:
1968 return -ENOIOCTLCMD;
1970 #ifdef AURORA_DEBUG
1971 printk("aurora_ioctl: end\n");
1972 #endif
1973 return 0;
1976 static void aurora_throttle(struct tty_struct * tty)
1978 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
1979 struct Aurora_board *bp;
1980 unsigned long flags;
1981 unsigned char chip;
1983 #ifdef AURORA_DEBUG
1984 printk("aurora_throttle: start\n");
1985 #endif
1986 if (aurora_paranoia_check(port, tty->device, "aurora_throttle"))
1987 return;
1989 bp = port_Board(port);
1990 chip=AURORA_CD180(port_No(port));
1992 save_flags(flags); cli();
1993 port->MSVR &= ~bp->RTS;
1994 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
1995 udelay(1);
1996 if (I_IXOFF(tty)) {
1997 aurora_wait_CCR(bp->r[chip]);
1998 bp->r[chip]->r[CD180_CCR]=CCR_SSCH2;
1999 aurora_wait_CCR(bp->r[chip]);
2001 bp->r[chip]->r[CD180_MSVR]=port->MSVR;
2002 restore_flags(flags);
2003 #ifdef AURORA_DEBUG
2004 printk("aurora_throttle: end\n");
2005 #endif
2008 static void aurora_unthrottle(struct tty_struct * tty)
2010 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
2011 struct Aurora_board *bp;
2012 unsigned long flags;
2013 unsigned char chip;
2015 #ifdef AURORA_DEBUG
2016 printk("aurora_unthrottle: start\n");
2017 #endif
2018 if (aurora_paranoia_check(port, tty->device, "aurora_unthrottle"))
2019 return;
2021 bp = port_Board(port);
2023 chip=AURORA_CD180(port_No(port));
2025 save_flags(flags); cli();
2026 port->MSVR |= bp->RTS;
2027 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
2028 udelay(1);
2029 if (I_IXOFF(tty)) {
2030 aurora_wait_CCR(bp->r[chip]);
2031 bp->r[chip]->r[CD180_CCR]=CCR_SSCH1;
2032 aurora_wait_CCR(bp->r[chip]);
2034 bp->r[chip]->r[CD180_MSVR]=port->MSVR;
2035 restore_flags(flags);
2036 #ifdef AURORA_DEBUG
2037 printk("aurora_unthrottle: end\n");
2038 #endif
2041 static void aurora_stop(struct tty_struct * tty)
2043 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
2044 struct Aurora_board *bp;
2045 unsigned long flags;
2046 unsigned char chip;
2048 #ifdef AURORA_DEBUG
2049 printk("aurora_stop: start\n");
2050 #endif
2051 if (aurora_paranoia_check(port, tty->device, "aurora_stop"))
2052 return;
2054 bp = port_Board(port);
2056 chip=AURORA_CD180(port_No(port));
2058 save_flags(flags); cli();
2059 port->SRER &= ~SRER_TXRDY;
2060 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
2061 udelay(1);
2062 bp->r[chip]->r[CD180_SRER]=port->SRER;
2063 restore_flags(flags);
2064 #ifdef AURORA_DEBUG
2065 printk("aurora_stop: end\n");
2066 #endif
2069 static void aurora_start(struct tty_struct * tty)
2071 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
2072 struct Aurora_board *bp;
2073 unsigned long flags;
2074 unsigned char chip;
2076 #ifdef AURORA_DEBUG
2077 printk("aurora_start: start\n");
2078 #endif
2079 if (aurora_paranoia_check(port, tty->device, "aurora_start"))
2080 return;
2082 bp = port_Board(port);
2084 chip=AURORA_CD180(port_No(port));
2086 save_flags(flags); cli();
2087 if (port->xmit_cnt && port->xmit_buf && !(port->SRER & SRER_TXRDY)) {
2088 port->SRER |= SRER_TXRDY;
2089 bp->r[chip]->r[CD180_CAR]=port_No(port)&7;
2090 udelay(1);
2091 bp->r[chip]->r[CD180_SRER]=port->SRER;
2093 restore_flags(flags);
2094 #ifdef AURORA_DEBUG
2095 printk("aurora_start: end\n");
2096 #endif
2100 * This routine is called from the scheduler tqueue when the interrupt
2101 * routine has signalled that a hangup has occurred. The path of
2102 * hangup processing is:
2104 * serial interrupt routine -> (scheduler tqueue) ->
2105 * do_aurora_hangup() -> tty->hangup() -> aurora_hangup()
2108 static void do_aurora_hangup(void *private_)
2110 struct Aurora_port *port = (struct Aurora_port *) private_;
2111 struct tty_struct *tty;
2113 #ifdef AURORA_DEBUG
2114 printk("do_aurora_hangup: start\n");
2115 #endif
2116 tty = port->tty;
2117 if (!tty)
2118 return;
2120 tty_hangup(tty);
2121 #ifdef AURORA_DEBUG
2122 printk("do_aurora_hangup: end\n");
2123 #endif
2126 static void aurora_hangup(struct tty_struct * tty)
2128 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
2129 struct Aurora_board *bp;
2131 #ifdef AURORA_DEBUG
2132 printk("aurora_hangup: start\n");
2133 #endif
2134 if (aurora_paranoia_check(port, tty->device, "aurora_hangup"))
2135 return;
2137 bp = port_Board(port);
2139 aurora_shutdown_port(bp, port);
2140 port->event = 0;
2141 port->count = 0;
2142 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
2143 port->tty = 0;
2144 wake_up_interruptible(&port->open_wait);
2145 #ifdef AURORA_DEBUG
2146 printk("aurora_hangup: end\n");
2147 #endif
2150 static void aurora_set_termios(struct tty_struct * tty, struct termios * old_termios)
2152 struct Aurora_port *port = (struct Aurora_port *)tty->driver_data;
2153 unsigned long flags;
2155 #ifdef AURORA_DEBUG
2156 printk("aurora_set_termios: start\n");
2157 #endif
2158 if (aurora_paranoia_check(port, tty->device, "aurora_set_termios"))
2159 return;
2161 if (tty->termios->c_cflag == old_termios->c_cflag &&
2162 tty->termios->c_iflag == old_termios->c_iflag)
2163 return;
2165 save_flags(flags); cli();
2166 aurora_change_speed(port_Board(port), port);
2167 restore_flags(flags);
2169 if ((old_termios->c_cflag & CRTSCTS) &&
2170 !(tty->termios->c_cflag & CRTSCTS)) {
2171 tty->hw_stopped = 0;
2172 aurora_start(tty);
2174 #ifdef AURORA_DEBUG
2175 printk("aurora_set_termios: end\n");
2176 #endif
2179 static void do_aurora_bh(void)
2181 run_task_queue(&tq_aurora);
2184 static void do_softint(void *private_)
2186 struct Aurora_port *port = (struct Aurora_port *) private_;
2187 struct tty_struct *tty;
2189 #ifdef AURORA_DEBUG
2190 printk("do_softint: start\n");
2191 #endif
2192 if(!(tty = port->tty))
2193 return;
2195 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
2196 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2197 tty->ldisc.write_wakeup)
2198 (tty->ldisc.write_wakeup)(tty);
2199 wake_up_interruptible(&tty->write_wait);
2201 #ifdef AURORA_DEBUG
2202 printk("do_softint: end\n");
2203 #endif
2206 static int aurora_init_drivers(void)
2208 int error;
2209 int i;
2211 #ifdef AURORA_DEBUG
2212 printk("aurora_init_drivers: start\n");
2213 #endif
2214 if (!(tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL))) {
2215 printk(KERN_ERR "aurora: Couldn't get free page.\n");
2216 return 1;
2218 init_bh(AURORA_BH, do_aurora_bh);
2219 /* memset(IRQ_to_board, 0, sizeof(IRQ_to_board));*/
2220 memset(&aurora_driver, 0, sizeof(aurora_driver));
2221 aurora_driver.magic = TTY_DRIVER_MAGIC;
2222 aurora_driver.name = "ttyA";
2223 aurora_driver.major = AURORA_MAJOR;
2224 aurora_driver.num = AURORA_TNPORTS;
2225 aurora_driver.type = TTY_DRIVER_TYPE_SERIAL;
2226 aurora_driver.subtype = AURORA_TYPE_NORMAL;
2227 aurora_driver.init_termios = tty_std_termios;
2228 aurora_driver.init_termios.c_cflag =
2229 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2230 aurora_driver.flags = TTY_DRIVER_REAL_RAW;
2231 aurora_driver.refcount = &aurora_refcount;
2232 aurora_driver.table = aurora_table;
2233 aurora_driver.termios = aurora_termios;
2234 aurora_driver.termios_locked = aurora_termios_locked;
2236 aurora_driver.open = aurora_open;
2237 aurora_driver.close = aurora_close;
2238 aurora_driver.write = aurora_write;
2239 aurora_driver.put_char = aurora_put_char;
2240 aurora_driver.flush_chars = aurora_flush_chars;
2241 aurora_driver.write_room = aurora_write_room;
2242 aurora_driver.chars_in_buffer = aurora_chars_in_buffer;
2243 aurora_driver.flush_buffer = aurora_flush_buffer;
2244 aurora_driver.ioctl = aurora_ioctl;
2245 aurora_driver.throttle = aurora_throttle;
2246 aurora_driver.unthrottle = aurora_unthrottle;
2247 aurora_driver.set_termios = aurora_set_termios;
2248 aurora_driver.stop = aurora_stop;
2249 aurora_driver.start = aurora_start;
2250 aurora_driver.hangup = aurora_hangup;
2252 if ((error = tty_register_driver(&aurora_driver))) {
2253 free_page((unsigned long)tmp_buf);
2254 printk(KERN_ERR "aurora: Couldn't register aurora driver, error = %d\n",
2255 error);
2256 return 1;
2259 memset(aurora_port, 0, sizeof(aurora_port));
2260 for (i = 0; i < AURORA_TNPORTS; i++) {
2261 aurora_port[i].normal_termios = aurora_driver.init_termios;
2262 aurora_port[i].magic = AURORA_MAGIC;
2263 aurora_port[i].tqueue.routine = do_softint;
2264 aurora_port[i].tqueue.data = &aurora_port[i];
2265 aurora_port[i].tqueue_hangup.routine = do_aurora_hangup;
2266 aurora_port[i].tqueue_hangup.data = &aurora_port[i];
2267 aurora_port[i].close_delay = 50 * HZ/100;
2268 aurora_port[i].closing_wait = 3000 * HZ/100;
2269 init_waitqueue_head(&aurora_port[i].open_wait);
2270 init_waitqueue_head(&aurora_port[i].close_wait);
2272 #ifdef AURORA_DEBUG
2273 printk("aurora_init_drivers: end\n");
2274 #endif
2275 return 0;
2278 static void aurora_release_drivers(void)
2280 #ifdef AURORA_DEBUG
2281 printk("aurora_release_drivers: start\n");
2282 #endif
2283 free_page((unsigned long)tmp_buf);
2284 tty_unregister_driver(&aurora_driver);
2285 #ifdef AURORA_DEBUG
2286 printk("aurora_release_drivers: end\n");
2287 #endif
2290 #ifndef MODULE
2292 * Called at boot time.
2294 * You can specify IO base for up to RC_NBOARD cards,
2295 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
2296 * Note that there will be no probing at default
2297 * addresses in this case.
2300 __init_func(void aurora_setup(char *str, int *ints))
2302 int i;
2304 for(i=0;(i<ints[0])&&(i<4);i++) {
2305 if (ints[i+1]) irqs[i]=ints[i+1];
2309 __init_func(int aurora_init(void))
2310 #else
2311 int aurora_init(void)
2312 #endif
2314 int found;
2315 int grrr,i;
2317 printk(KERN_INFO "aurora: Driver starting.\n");
2318 if(aurora_init_drivers())return -EIO;
2319 found=aurora_probe();
2320 if(!found){
2321 aurora_release_drivers();
2322 printk(KERN_INFO "aurora: No Aurora Multiport boards detected.\n");
2323 return -EIO;
2324 } else {
2325 printk(KERN_INFO "aurora: %d boards found.\n",found);
2327 for(i=0;i<found;i++){
2328 if ((grrr = aurora_setup_board(&aurora_board[i]))) {
2329 #ifdef AURORA_DEBUG
2330 printk(KERN_ERR "aurora_init: error aurora_setup_board ret %d\n",grrr);
2331 #endif
2332 return grrr;
2335 return 0;
2338 #ifdef MODULE
2339 int irq = 0;
2340 int irq1 = 0;
2341 int irq2 = 0;
2342 int irq3 = 0;
2343 MODULE_PARM(irq , "i");
2344 MODULE_PARM(irq1, "i");
2345 MODULE_PARM(irq2, "i");
2346 MODULE_PARM(irq3, "i");
2348 int init_module(void)
2350 if (irq ) irqs[0]=irq ;
2351 if (irq1) irqs[1]=irq1;
2352 if (irq2) irqs[2]=irq2;
2353 if (irq3) irqs[3]=irq3;
2354 return aurora_init();
2357 void cleanup_module(void)
2359 int i;
2361 #ifdef AURORA_DEBUG
2362 printk("cleanup_module: aurora_release_drivers\n");
2363 #endif;
2365 aurora_release_drivers();
2366 for (i = 0; i < AURORA_NBOARD; i++)
2367 if (aurora_board[i].flags & AURORA_BOARD_PRESENT) {
2368 aurora_shutdown_board(&aurora_board[i]);
2369 aurora_release_io_range(&aurora_board[i]);
2372 #endif /* MODULE */