1 /* $Id: aurora.c,v 1.19 2002/01/08 16:00:16 davem Exp $
2 * linux/drivers/sbus/char/aurora.c -- Aurora multiport driver
4 * Copyright (c) 1999 by Oliver Aldulea (oli at bv dot 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.
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.
37 * n.b. The board can support 115.2 bit rates, but only on a few
38 * ports. The total badwidth of one chip (ports 0-7 or 8-15) is equal
39 * to OSC_FREQ div 16. In case of my board, each chip can take 6
40 * channels of 115.2 kbaud. This information is not well-tested.
42 * Fixed to use tty_get_baud_rate().
43 * Theodore Ts'o <tytso@mit.edu>, 2001-Oct-12
46 #include <linux/module.h>
48 #include <linux/errno.h>
49 #include <linux/sched.h>
50 #ifdef AURORA_INT_DEBUG
51 #include <linux/timer.h>
53 #include <linux/interrupt.h>
54 #include <linux/tty.h>
55 #include <linux/tty_flip.h>
56 #include <linux/major.h>
57 #include <linux/string.h>
58 #include <linux/fcntl.h>
60 #include <linux/kernel.h>
61 #include <linux/init.h>
62 #include <linux/delay.h>
63 #include <linux/bitops.h>
67 #include <asm/oplib.h>
68 #include <asm/system.h>
69 #include <asm/kdebug.h>
71 #include <asm/uaccess.h>
76 unsigned char irqs[4] = {
80 #ifdef AURORA_INT_DEBUG
84 static struct tty_driver *aurora_driver;
85 static struct Aurora_board aurora_board[AURORA_NBOARD] = {
89 static struct Aurora_port aurora_port[AURORA_TNPORTS] = {
93 /* no longer used. static struct Aurora_board * IRQ_to_board[16] = { NULL, } ;*/
94 static unsigned char * tmp_buf = NULL;
96 DECLARE_TASK_QUEUE(tq_aurora);
98 static inline int aurora_paranoia_check(struct Aurora_port const * port,
99 char *name, const char *routine)
101 #ifdef AURORA_PARANOIA_CHECK
102 static const char *badmagic =
103 KERN_DEBUG "aurora: Warning: bad aurora port magic number for device %s in %s\n";
104 static const char *badinfo =
105 KERN_DEBUG "aurora: Warning: null aurora port for device %s in %s\n";
108 printk(badinfo, name, routine);
111 if (port->magic != AURORA_MAGIC) {
112 printk(badmagic, name, routine);
121 * Service functions for aurora driver.
125 /* Get board number from pointer */
126 static inline int board_No (struct Aurora_board const * bp)
128 return bp - aurora_board;
131 /* Get port number from pointer */
132 static inline int port_No (struct Aurora_port const * port)
134 return AURORA_PORT(port - aurora_port);
137 /* Get pointer to board from pointer to port */
138 static inline struct Aurora_board * port_Board(struct Aurora_port const * port)
140 return &aurora_board[AURORA_BOARD(port - aurora_port)];
143 /* Wait for Channel Command Register ready */
144 static inline void aurora_wait_CCR(struct aurora_reg128 * r)
149 printk("aurora_wait_CCR\n");
151 /* FIXME: need something more descriptive than 100000 :) */
152 for (delay = 100000; delay; delay--)
153 if (!sbus_readb(&r->r[CD180_CCR]))
155 printk(KERN_DEBUG "aurora: Timeout waiting for CCR.\n");
159 * aurora probe functions.
162 /* Must be called with enabled interrupts */
163 static inline void aurora_long_delay(unsigned long delay)
168 printk("aurora_long_delay: start\n");
170 for (i = jiffies + delay; time_before(jiffies, i); ) ;
172 printk("aurora_long_delay: end\n");
176 /* Reset and setup CD180 chip */
177 static int aurora_init_CD180(struct Aurora_board * bp, int chip)
183 printk("aurora_init_CD180: start %d:%d\n",
186 save_flags(flags); cli();
187 sbus_writeb(0, &bp->r[chip]->r[CD180_CAR]);
188 sbus_writeb(0, &bp->r[chip]->r[CD180_GSVR]);
190 /* Wait for CCR ready */
191 aurora_wait_CCR(bp->r[chip]);
193 /* Reset CD180 chip */
194 sbus_writeb(CCR_HARDRESET, &bp->r[chip]->r[CD180_CCR]);
199 (sbus_readb(&bp->r[chip]->r[CD180_GSVR])!=0xff))udelay(100);
201 printk(KERN_ERR "aurora%d: Chip %d failed init.\n",
203 restore_flags(flags);
207 sbus_writeb((board_No(bp)<<5)|((chip+1)<<3),
208 &bp->r[chip]->r[CD180_GSVR]); /* Set ID for this chip */
209 sbus_writeb(0x80|bp->ACK_MINT,
210 &bp->r[chip]->r[CD180_MSMR]); /* Prio for modem intr */
211 sbus_writeb(0x80|bp->ACK_TINT,
212 &bp->r[chip]->r[CD180_TSMR]); /* Prio for transmitter intr */
213 sbus_writeb(0x80|bp->ACK_RINT,
214 &bp->r[chip]->r[CD180_RSMR]); /* Prio for receiver intr */
215 /* Setting up prescaler. We need 4 tick per 1 ms */
216 sbus_writeb((bp->oscfreq/(1000000/AURORA_TPS)) >> 8,
217 &bp->r[chip]->r[CD180_PPRH]);
218 sbus_writeb((bp->oscfreq/(1000000/AURORA_TPS)) & 0xff,
219 &bp->r[chip]->r[CD180_PPRL]);
221 sbus_writeb(SRCR_AUTOPRI|SRCR_GLOBPRI,
222 &bp->r[chip]->r[CD180_SRCR]);
224 id = sbus_readb(&bp->r[chip]->r[CD180_GFRCR]);
225 printk(KERN_INFO "aurora%d: Chip %d id %02x: ",
226 board_No(bp), chip,id);
227 if(sbus_readb(&bp->r[chip]->r[CD180_SRCR]) & 128) {
229 case 0x82:printk("CL-CD1864 rev A\n");break;
230 case 0x83:printk("CL-CD1865 rev A\n");break;
231 case 0x84:printk("CL-CD1865 rev B\n");break;
232 case 0x85:printk("CL-CD1865 rev C\n");break;
233 default:printk("Unknown.\n");
237 case 0x81:printk("CL-CD180 rev B\n");break;
238 case 0x82:printk("CL-CD180 rev C\n");break;
239 default:printk("Unknown.\n");
242 restore_flags(flags);
244 printk("aurora_init_CD180: end\n");
249 static int valid_irq(unsigned char irq)
252 for(i=0;i<TYPE_1_IRQS;i++)
253 if (type_1_irq[i]==irq) return 1;
257 static irqreturn_t aurora_interrupt(int irq, void * dev_id, struct pt_regs * regs);
259 /* Main probing routine, also sets irq. */
260 static int aurora_probe(void)
262 struct sbus_bus *sbus;
263 struct sbus_dev *sdev;
267 struct Aurora_board *bp;
269 for_each_sbus(sbus) {
270 for_each_sbusdev(sdev, sbus) {
271 /* printk("Try: %x %s\n",sdev,sdev->prom_name);*/
272 if (!strcmp(sdev->prom_name, "sio16")) {
274 printk(KERN_INFO "aurora: sio16 at %p\n",sdev);
276 if((sdev->reg_addrs[0].reg_size!=1) &&
277 (sdev->reg_addrs[1].reg_size!=128) &&
278 (sdev->reg_addrs[2].reg_size!=128) &&
279 (sdev->reg_addrs[3].reg_size!=4)) {
280 printk(KERN_ERR "aurora%d: registers' sizes "
281 "do not match.\n", bn);
284 bp = &aurora_board[bn];
285 bp->r0 = (struct aurora_reg1 *)
286 sbus_ioremap(&sdev->resource[0], 0,
287 sdev->reg_addrs[0].reg_size,
289 if (bp->r0 == NULL) {
290 printk(KERN_ERR "aurora%d: can't map "
291 "reg_addrs[0]\n", bn);
295 printk("Map reg 0: %p\n", bp->r0);
297 bp->r[0] = (struct aurora_reg128 *)
298 sbus_ioremap(&sdev->resource[1], 0,
299 sdev->reg_addrs[1].reg_size,
301 if (bp->r[0] == NULL) {
302 printk(KERN_ERR "aurora%d: can't map "
303 "reg_addrs[1]\n", bn);
307 printk("Map reg 1: %p\n", bp->r[0]);
309 bp->r[1] = (struct aurora_reg128 *)
310 sbus_ioremap(&sdev->resource[2], 0,
311 sdev->reg_addrs[2].reg_size,
313 if (bp->r[1] == NULL) {
314 printk(KERN_ERR "aurora%d: can't map "
315 "reg_addrs[2]\n", bn);
319 printk("Map reg 2: %p\n", bp->r[1]);
321 bp->r3 = (struct aurora_reg4 *)
322 sbus_ioremap(&sdev->resource[3], 0,
323 sdev->reg_addrs[3].reg_size,
325 if (bp->r3 == NULL) {
326 printk(KERN_ERR "aurora%d: can't map "
327 "reg_addrs[3]\n", bn);
331 printk("Map reg 3: %p\n", bp->r3);
333 /* Variables setup */
336 grrr=prom_getint(sdev->prom_node,"intr");
337 printk("intr pri %d\n", grrr);
339 if ((bp->irq=irqs[bn]) && valid_irq(bp->irq) &&
340 !request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
341 free_irq(bp->irq|0x30, bp);
343 if ((bp->irq=prom_getint(sdev->prom_node, "bintr")) && valid_irq(bp->irq) &&
344 !request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
345 free_irq(bp->irq|0x30, bp);
347 if ((bp->irq=prom_getint(sdev->prom_node, "intr")) && valid_irq(bp->irq) &&
348 !request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
349 free_irq(bp->irq|0x30, bp);
351 for(grrr=0;grrr<TYPE_1_IRQS;grrr++) {
352 if ((bp->irq=type_1_irq[grrr])&&!request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
353 free_irq(bp->irq|0x30, bp);
356 printk(KERN_ERR "aurora%d: Could not get an irq for this board !!!\n",bn);
360 if(bp->flags==0xff)break;
361 printk(KERN_INFO "aurora%d: irq %d\n",bn,bp->irq&0x0f);
363 grrr=prom_getproperty(sdev->prom_node,"dtr_rts",buf,sizeof(buf));
364 if(!strcmp(buf,"swapped")){
365 printk(KERN_INFO "aurora%d: Swapped DTR and RTS\n",bn);
368 bp->MSVDTR=CD180_MSVRTS;
369 bp->MSVRTS=CD180_MSVDTR;
370 bp->flags|=AURORA_BOARD_DTR_FLOW_OK;
372 #ifdef AURORA_FORCE_DTR_FLOW
373 printk(KERN_INFO "aurora%d: Forcing swapped DTR-RTS\n",bn);
376 bp->MSVDTR=CD180_MSVRTS;
377 bp->MSVRTS=CD180_MSVDTR;
378 bp->flags|=AURORA_BOARD_DTR_FLOW_OK;
380 printk(KERN_INFO "aurora%d: Normal DTR and RTS\n",bn);
383 bp->MSVDTR=CD180_MSVDTR;
384 bp->MSVRTS=CD180_MSVRTS;
387 bp->oscfreq=prom_getint(sdev->prom_node,"clk")*100;
388 printk(KERN_INFO "aurora%d: Oscillator: %d Hz\n",bn,bp->oscfreq);
389 grrr=prom_getproperty(sdev->prom_node,"chip",buf,sizeof(buf));
390 printk(KERN_INFO "aurora%d: Chips: %s\n",bn,buf);
391 grrr=prom_getproperty(sdev->prom_node,"manu",buf,sizeof(buf));
392 printk(KERN_INFO "aurora%d: Manufacturer: %s\n",bn,buf);
393 grrr=prom_getproperty(sdev->prom_node,"model",buf,sizeof(buf));
394 printk(KERN_INFO "aurora%d: Model: %s\n",bn,buf);
395 grrr=prom_getproperty(sdev->prom_node,"rev",buf,sizeof(buf));
396 printk(KERN_INFO "aurora%d: Revision: %s\n",bn,buf);
397 grrr=prom_getproperty(sdev->prom_node,"mode",buf,sizeof(buf));
398 printk(KERN_INFO "aurora%d: Mode: %s\n",bn,buf);
402 bp->flags = AURORA_BOARD_PRESENT;
414 static void aurora_release_io_range(struct Aurora_board *bp)
416 sbus_iounmap((unsigned long)bp->r0, 1);
417 sbus_iounmap((unsigned long)bp->r[0], 128);
418 sbus_iounmap((unsigned long)bp->r[1], 128);
419 sbus_iounmap((unsigned long)bp->r3, 4);
422 static inline void aurora_mark_event(struct Aurora_port * port, int event)
425 printk("aurora_mark_event: start\n");
427 set_bit(event, &port->event);
428 queue_task(&port->tqueue, &tq_aurora);
431 printk("aurora_mark_event: end\n");
435 static __inline__ struct Aurora_port * aurora_get_port(struct Aurora_board const * bp,
437 unsigned char const *what)
439 unsigned char channel;
440 struct Aurora_port * port;
442 channel = ((chip << 3) |
443 ((sbus_readb(&bp->r[chip]->r[CD180_GSCR]) & GSCR_CHAN) >> GSCR_CHAN_OFF));
444 port = &aurora_port[board_No(bp) * AURORA_NPORT * AURORA_NCD180 + channel];
445 if (port->flags & ASYNC_INITIALIZED)
448 printk(KERN_DEBUG "aurora%d: %s interrupt from invalid port %d\n",
449 board_No(bp), what, channel);
453 static void aurora_receive_exc(struct Aurora_board const * bp, int chip)
455 struct Aurora_port *port;
456 struct tty_struct *tty;
457 unsigned char status;
460 if (!(port = aurora_get_port(bp, chip, "Receive_x")))
464 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
465 #ifdef AURORA_INTNORM
466 printk("aurora%d: port %d: Working around flip buffer overflow.\n",
467 board_No(bp), port_No(port));
472 #ifdef AURORA_REPORT_OVERRUN
473 status = sbus_readb(&bp->r[chip]->r[CD180_RCSR]);
474 if (status & RCSR_OE) {
477 printk("aurora%d: port %d: Overrun. Total %ld overruns.\n",
478 board_No(bp), port_No(port), port->overrun);
481 status &= port->mark_mask;
483 status = sbus_readb(&bp->r[chip]->r[CD180_RCSR]) & port->mark_mask;
485 ch = sbus_readb(&bp->r[chip]->r[CD180_RDR]);
489 if (status & RCSR_TOUT) {
490 /* printk("aurora%d: port %d: Receiver timeout. Hardware problems ?\n",
491 board_No(bp), port_No(port));*/
494 } else if (status & RCSR_BREAK) {
495 printk(KERN_DEBUG "aurora%d: port %d: Handling break...\n",
496 board_No(bp), port_No(port));
497 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
498 if (port->flags & ASYNC_SAK)
501 } else if (status & RCSR_PE)
502 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
504 else if (status & RCSR_FE)
505 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
507 else if (status & RCSR_OE)
508 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
511 *tty->flip.flag_buf_ptr++ = 0;
513 *tty->flip.char_buf_ptr++ = ch;
515 queue_task(&tty->flip.tqueue, &tq_timer);
518 static void aurora_receive(struct Aurora_board const * bp, int chip)
520 struct Aurora_port *port;
521 struct tty_struct *tty;
522 unsigned char count,cnt;
524 if (!(port = aurora_get_port(bp, chip, "Receive")))
529 count = sbus_readb(&bp->r[chip]->r[CD180_RDCR]);
531 #ifdef AURORA_REPORT_FIFO
532 port->hits[count > 8 ? 9 : count]++;
536 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
537 #ifdef AURORA_INTNORM
538 printk("aurora%d: port %d: Working around flip buffer overflow.\n",
539 board_No(bp), port_No(port));
543 cnt = sbus_readb(&bp->r[chip]->r[CD180_RDR]);
544 *tty->flip.char_buf_ptr++ = cnt;
545 *tty->flip.flag_buf_ptr++ = 0;
548 queue_task(&tty->flip.tqueue, &tq_timer);
551 static void aurora_transmit(struct Aurora_board const * bp, int chip)
553 struct Aurora_port *port;
554 struct tty_struct *tty;
557 if (!(port = aurora_get_port(bp, chip, "Transmit")))
562 if (port->SRER & SRER_TXEMPTY) {
564 sbus_writeb(port_No(port) & 7,
565 &bp->r[chip]->r[CD180_CAR]);
567 port->SRER &= ~SRER_TXEMPTY;
568 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
572 if ((port->xmit_cnt <= 0 && !port->break_length)
573 || tty->stopped || tty->hw_stopped) {
574 sbus_writeb(port_No(port) & 7,
575 &bp->r[chip]->r[CD180_CAR]);
577 port->SRER &= ~SRER_TXRDY;
578 sbus_writeb(port->SRER,
579 &bp->r[chip]->r[CD180_SRER]);
583 if (port->break_length) {
584 if (port->break_length > 0) {
585 if (port->COR2 & COR2_ETC) {
586 sbus_writeb(CD180_C_ESC,
587 &bp->r[chip]->r[CD180_TDR]);
588 sbus_writeb(CD180_C_SBRK,
589 &bp->r[chip]->r[CD180_TDR]);
590 port->COR2 &= ~COR2_ETC;
592 count = min(port->break_length, 0xff);
593 sbus_writeb(CD180_C_ESC,
594 &bp->r[chip]->r[CD180_TDR]);
595 sbus_writeb(CD180_C_DELAY,
596 &bp->r[chip]->r[CD180_TDR]);
598 &bp->r[chip]->r[CD180_TDR]);
599 if (!(port->break_length -= count))
600 port->break_length--;
602 sbus_writeb(CD180_C_ESC,
603 &bp->r[chip]->r[CD180_TDR]);
604 sbus_writeb(CD180_C_EBRK,
605 &bp->r[chip]->r[CD180_TDR]);
606 sbus_writeb(port->COR2,
607 &bp->r[chip]->r[CD180_COR2]);
608 aurora_wait_CCR(bp->r[chip]);
609 sbus_writeb(CCR_CORCHG2,
610 &bp->r[chip]->r[CD180_CCR]);
611 port->break_length = 0;
618 u8 byte = port->xmit_buf[port->xmit_tail++];
620 sbus_writeb(byte, &bp->r[chip]->r[CD180_TDR]);
621 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
622 if (--port->xmit_cnt <= 0)
624 } while (--count > 0);
626 if (port->xmit_cnt <= 0) {
627 sbus_writeb(port_No(port) & 7,
628 &bp->r[chip]->r[CD180_CAR]);
630 port->SRER &= ~SRER_TXRDY;
631 sbus_writeb(port->SRER,
632 &bp->r[chip]->r[CD180_SRER]);
634 if (port->xmit_cnt <= port->wakeup_chars)
635 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
638 static void aurora_check_modem(struct Aurora_board const * bp, int chip)
640 struct Aurora_port *port;
641 struct tty_struct *tty;
644 if (!(port = aurora_get_port(bp, chip, "Modem")))
649 mcr = sbus_readb(&bp->r[chip]->r[CD180_MCR]);
650 if (mcr & MCR_CDCHG) {
651 if (sbus_readb(&bp->r[chip]->r[CD180_MSVR]) & MSVR_CD)
652 wake_up_interruptible(&port->open_wait);
654 schedule_task(&port->tqueue_hangup);
657 /* 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
658 * Aurora didn't made any boards with CTS or DSR broken...
660 /* #ifdef AURORA_BRAIN_DAMAGED_CTS
661 if (mcr & MCR_CTSCHG) {
662 if (aurora_in(bp, CD180_MSVR) & MSVR_CTS) {
664 port->SRER |= SRER_TXRDY;
665 if (port->xmit_cnt <= port->wakeup_chars)
666 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
669 port->SRER &= ~SRER_TXRDY;
671 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
673 if (mcr & MCR_DSRCHG) {
674 if (aurora_in(bp, CD180_MSVR) & MSVR_DSR) {
676 port->SRER |= SRER_TXRDY;
677 if (port->xmit_cnt <= port->wakeup_chars)
678 aurora_mark_event(port, RS_EVENT_WRITE_WAKEUP);
681 port->SRER &= ~SRER_TXRDY;
683 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
685 #endif AURORA_BRAIN_DAMAGED_CTS */
687 /* Clear change bits */
688 sbus_writeb(0, &bp->r[chip]->r[CD180_MCR]);
691 /* The main interrupt processing routine */
692 static irqreturn_t aurora_interrupt(int irq, void * dev_id, struct pt_regs * regs)
694 unsigned char status;
695 unsigned char ack,chip/*,chip_id*/;
696 struct Aurora_board * bp = (struct Aurora_board *) dev_id;
697 unsigned long loop = 0;
699 #ifdef AURORA_INT_DEBUG
700 printk("IRQ%d %d\n",irq,++irqhit);
701 #ifdef AURORA_FLOODPRO
702 if (irqhit>=AURORA_FLOODPRO)
703 sbus_writeb(8, &bp->r0->r);
707 /* old bp = IRQ_to_board[irq&0x0f];*/
709 if (!bp || !(bp->flags & AURORA_BOARD_ACTIVE))
712 /* The while() below takes care of this.
713 status = sbus_readb(&bp->r[0]->r[CD180_SRSR]);
714 #ifdef AURORA_INT_DEBUG
715 printk("mumu: %02x\n", status);
717 if (!(status&SRSR_ANYINT))
718 return IRQ_NONE; * Nobody has anything to say, so exit *
720 while ((loop++ < 48) &&
721 (status = sbus_readb(&bp->r[0]->r[CD180_SRSR]) & SRSR_ANYINT)){
722 #ifdef AURORA_INT_DEBUG
723 printk("SRSR: %02x\n", status);
725 if (status & SRSR_REXT) {
726 ack = sbus_readb(&bp->r3->r[bp->ACK_RINT]);
727 #ifdef AURORA_INT_DEBUG
728 printk("R-ACK %02x\n", ack);
730 if ((ack >> 5) == board_No(bp)) {
731 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
732 if ((ack&GSVR_ITMASK)==GSVR_IT_RGD) {
733 aurora_receive(bp,chip);
735 &bp->r[chip]->r[CD180_EOSRR]);
736 } else if ((ack & GSVR_ITMASK) == GSVR_IT_REXC) {
737 aurora_receive_exc(bp,chip);
739 &bp->r[chip]->r[CD180_EOSRR]);
743 } else if (status & SRSR_TEXT) {
744 ack = sbus_readb(&bp->r3->r[bp->ACK_TINT]);
745 #ifdef AURORA_INT_DEBUG
746 printk("T-ACK %02x\n", ack);
748 if ((ack >> 5) == board_No(bp)) {
749 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
750 if ((ack&GSVR_ITMASK)==GSVR_IT_TX) {
751 aurora_transmit(bp,chip);
753 &bp->r[chip]->r[CD180_EOSRR]);
757 } else if (status & SRSR_MEXT) {
758 ack = sbus_readb(&bp->r3->r[bp->ACK_MINT]);
759 #ifdef AURORA_INT_DEBUG
760 printk("M-ACK %02x\n", ack);
762 if ((ack >> 5) == board_No(bp)) {
763 if ((chip = ((ack>>3)&3)-1) < AURORA_NCD180) {
764 if ((ack&GSVR_ITMASK)==GSVR_IT_MDM) {
765 aurora_check_modem(bp,chip);
767 &bp->r[chip]->r[CD180_EOSRR]);
773 /* I guess this faster code can be used with CD1865, using AUROPRI and GLOBPRI. */
775 while ((loop++ < 48)&&(status=bp->r[0]->r[CD180_SRSR]&SRSR_ANYINT)){
776 #ifdef AURORA_INT_DEBUG
777 printk("SRSR: %02x\n",status);
779 ack = sbus_readb(&bp->r3->r[0]);
780 #ifdef AURORA_INT_DEBUG
781 printk("ACK: %02x\n",ack);
783 if ((ack>>5)==board_No(bp)) {
784 if ((chip=((ack>>3)&3)-1) < AURORA_NCD180) {
786 if (ack==GSVR_IT_RGD) {
787 aurora_receive(bp,chip);
789 &bp->r[chip]->r[CD180_EOSRR]);
790 } else if (ack==GSVR_IT_REXC) {
791 aurora_receive_exc(bp,chip);
793 &bp->r[chip]->r[CD180_EOSRR]);
794 } else if (ack==GSVR_IT_TX) {
795 aurora_transmit(bp,chip);
797 &bp->r[chip]->r[CD180_EOSRR]);
798 } else if (ack==GSVR_IT_MDM) {
799 aurora_check_modem(bp,chip);
801 &bp->r[chip]->r[CD180_EOSRR]);
808 /* This is the old handling routine, used in riscom8 for only one CD180. I keep it here for reference. */
810 for(chip=0;chip<AURORA_NCD180;chip++){
811 chip_id=(board_No(bp)<<5)|((chip+1)<<3);
813 while ((loop++ < 1) &&
814 ((status = sbus_readb(&bp->r[chip]->r[CD180_SRSR])) &
815 (SRSR_TEXT | SRSR_MEXT | SRSR_REXT))) {
817 if (status & SRSR_REXT) {
818 ack = sbus_readb(&bp->r3->r[bp->ACK_RINT]);
819 if (ack == (chip_id | GSVR_IT_RGD)) {
823 aurora_receive(bp,chip);
824 } else if (ack == (chip_id | GSVR_IT_REXC)) {
828 aurora_receive_exc(bp,chip);
830 #ifdef AURORA_INTNORM
831 printk("aurora%d-%d: Bad receive ack 0x%02x.\n",
832 board_No(bp), chip, ack);
835 } else if (status & SRSR_TEXT) {
836 ack = sbus_readb(&bp->r3->r[bp->ACK_TINT]);
837 if (ack == (chip_id | GSVR_IT_TX)){
841 aurora_transmit(bp,chip);
843 #ifdef AURORA_INTNORM
844 printk("aurora%d-%d: Bad transmit ack 0x%02x.\n",
845 board_No(bp), chip, ack);
848 } else if (status & SRSR_MEXT) {
849 ack = sbus_readb(&bp->r3->r[bp->ACK_MINT]);
850 if (ack == (chip_id | GSVR_IT_MDM)){
854 aurora_check_modem(bp,chip);
856 #ifdef AURORA_INTNORM
857 printk("aurora%d-%d: Bad modem ack 0x%02x.\n",
858 board_No(bp), chip, ack);
862 sbus_writeb(0, &bp->r[chip]->r[CD180_EOSRR]);
870 #ifdef AURORA_INT_DEBUG
871 static void aurora_timer (unsigned long ignored);
873 static DEFINE_TIMER(aurora_poll_timer, aurora_timer, 0, 0);
876 aurora_timer (unsigned long ignored)
881 save_flags(flags); cli();
883 printk("SRSR: %02x,%02x - ",
884 sbus_readb(&aurora_board[0].r[0]->r[CD180_SRSR]),
885 sbus_readb(&aurora_board[0].r[1]->r[CD180_SRSR]));
886 for (i = 0; i < 4; i++) {
889 sbus_readb(&aurora_board[0].r3->r[i]));
893 aurora_poll_timer.expires = jiffies + 300;
894 add_timer (&aurora_poll_timer);
896 restore_flags(flags);
901 * Routines for open & close processing.
904 /* Called with disabled interrupts */
905 static int aurora_setup_board(struct Aurora_board * bp)
911 for (i = 0; i < AURORA_ALLIRQ; i++) {
912 error = request_irq(allirq[i]|0x30, aurora_interrupt, IRQF_SHARED,
915 printk(KERN_ERR "IRQ%d request error %d\n",
919 error = request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED,
922 printk(KERN_ERR "IRQ request error %d\n", error);
927 sbus_writeb(0, &bp->r0->r);
929 if (bp->flags & AURORA_BOARD_TYPE_2) {
932 sbus_writeb((AURORA_CFG_ENABLE_IO | AURORA_CFG_ENABLE_IRQ |
933 (((bp->irq)&0x0f)>>2)),
938 if (aurora_init_CD180(bp,0))error=1;error=0;
939 if (aurora_init_CD180(bp,1))error++;
940 if (error == AURORA_NCD180) {
941 printk(KERN_ERR "Both chips failed initialisation.\n");
945 #ifdef AURORA_INT_DEBUG
946 aurora_poll_timer.expires= jiffies + 1;
947 add_timer(&aurora_poll_timer);
950 printk("aurora_setup_board: end\n");
955 /* Called with disabled interrupts */
956 static void aurora_shutdown_board(struct Aurora_board *bp)
961 printk("aurora_shutdown_board: start\n");
964 #ifdef AURORA_INT_DEBUG
965 del_timer(&aurora_poll_timer);
969 for(i=0;i<AURORA_ALLIRQ;i++){
970 free_irq(allirq[i]|0x30, bp);
971 /* IRQ_to_board[allirq[i]&0xf] = NULL;*/
974 free_irq(bp->irq|0x30, bp);
975 /* IRQ_to_board[bp->irq&0xf] = NULL;*/
979 sbus_writeb(i & 7, &bp->r[i>>3]->r[CD180_CAR]);
981 sbus_writeb(0, &bp->r[i>>3]->r[CD180_MSVR]);
985 sbus_writeb(0, &bp->r0->r);
988 printk("aurora_shutdown_board: end\n");
992 /* Setting up port characteristics.
993 * Must be called with disabled interrupts
995 static void aurora_change_speed(struct Aurora_board *bp, struct Aurora_port *port)
997 struct tty_struct *tty;
1000 unsigned char cor1 = 0, cor3 = 0;
1001 unsigned char mcor1 = 0, mcor2 = 0,chip;
1004 printk("aurora_change_speed: start\n");
1006 if (!(tty = port->tty) || !tty->termios)
1009 chip = AURORA_CD180(port_No(port));
1013 port->MSVR = MSVR_RTS|MSVR_DTR;
1015 baud = tty_get_baud_rate(tty);
1017 /* Select port on the board */
1018 sbus_writeb(port_No(port) & 7,
1019 &bp->r[chip]->r[CD180_CAR]);
1023 /* Drop DTR & exit */
1024 port->MSVR &= ~(bp->DTR|bp->RTS);
1025 sbus_writeb(port->MSVR,
1026 &bp->r[chip]->r[CD180_MSVR]);
1030 port->MSVR |= bp->DTR;
1031 sbus_writeb(port->MSVR,
1032 &bp->r[chip]->r[CD180_MSVR]);
1035 /* Now we must calculate some speed dependent things. */
1037 /* Set baud rate for port. */
1038 tmp = (((bp->oscfreq + baud/2) / baud +
1039 CD180_TPC/2) / CD180_TPC);
1041 /* tmp = (bp->oscfreq/7)/baud;
1042 if((tmp%10)>4)tmp=tmp/10+1;else tmp=tmp/10;*/
1043 /* printk("Prescaler period: %d\n",tmp);*/
1045 sbus_writeb((tmp >> 8) & 0xff,
1046 &bp->r[chip]->r[CD180_RBPRH]);
1047 sbus_writeb((tmp >> 8) & 0xff,
1048 &bp->r[chip]->r[CD180_TBPRH]);
1049 sbus_writeb(tmp & 0xff, &bp->r[chip]->r[CD180_RBPRL]);
1050 sbus_writeb(tmp & 0xff, &bp->r[chip]->r[CD180_TBPRL]);
1052 baud = (baud + 5) / 10; /* Estimated CPS */
1054 /* Two timer ticks seems enough to wakeup something like SLIP driver */
1055 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
1056 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
1057 SERIAL_XMIT_SIZE - 1 : tmp);
1059 /* Receiver timeout will be transmission time for 1.5 chars */
1060 tmp = (AURORA_TPS + AURORA_TPS/2 + baud/2) / baud;
1061 tmp = (tmp > 0xff) ? 0xff : tmp;
1062 sbus_writeb(tmp, &bp->r[chip]->r[CD180_RTPR]);
1064 switch (C_CSIZE(tty)) {
1082 cor1 |= COR1_IGNORE;
1083 if (C_PARENB(tty)) {
1084 cor1 |= COR1_NORMPAR;
1088 cor1 &= ~COR1_IGNORE;
1090 /* Set marking of some errors */
1091 port->mark_mask = RCSR_OE | RCSR_TOUT;
1093 port->mark_mask |= RCSR_FE | RCSR_PE;
1094 if (I_BRKINT(tty) || I_PARMRK(tty))
1095 port->mark_mask |= RCSR_BREAK;
1097 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
1098 if (I_IGNBRK(tty)) {
1099 port->mark_mask &= ~RCSR_BREAK;
1101 /* Real raw mode. Ignore all */
1102 port->mark_mask &= ~RCSR_OE;
1104 /* Enable Hardware Flow Control */
1105 if (C_CRTSCTS(tty)) {
1106 /*#ifdef AURORA_BRAIN_DAMAGED_CTS
1107 port->SRER |= SRER_DSR | SRER_CTS;
1108 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
1109 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
1110 tty->hw_stopped = !(aurora_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR));
1112 port->COR2 |= COR2_CTSAE;
1114 if (bp->flags&AURORA_BOARD_DTR_FLOW_OK) {
1115 mcor1 |= AURORA_RXTH;
1118 /* Enable Software Flow Control. FIXME: I'm not sure about this */
1119 /* Some people reported that it works, but I still doubt */
1121 port->COR2 |= COR2_TXIBE;
1122 cor3 |= (COR3_FCT | COR3_SCDE);
1124 port->COR2 |= COR2_IXM;
1125 sbus_writeb(START_CHAR(tty),
1126 &bp->r[chip]->r[CD180_SCHR1]);
1127 sbus_writeb(STOP_CHAR(tty),
1128 &bp->r[chip]->r[CD180_SCHR2]);
1129 sbus_writeb(START_CHAR(tty),
1130 &bp->r[chip]->r[CD180_SCHR3]);
1131 sbus_writeb(STOP_CHAR(tty),
1132 &bp->r[chip]->r[CD180_SCHR4]);
1134 if (!C_CLOCAL(tty)) {
1135 /* Enable CD check */
1136 port->SRER |= SRER_CD;
1137 mcor1 |= MCOR1_CDZD;
1138 mcor2 |= MCOR2_CDOD;
1142 /* Enable receiver */
1143 port->SRER |= SRER_RXD;
1145 /* Set input FIFO size (1-8 bytes) */
1146 cor3 |= AURORA_RXFIFO;
1147 /* Setting up CD180 channel registers */
1148 sbus_writeb(cor1, &bp->r[chip]->r[CD180_COR1]);
1149 sbus_writeb(port->COR2, &bp->r[chip]->r[CD180_COR2]);
1150 sbus_writeb(cor3, &bp->r[chip]->r[CD180_COR3]);
1151 /* Make CD180 know about registers change */
1152 aurora_wait_CCR(bp->r[chip]);
1153 sbus_writeb(CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3,
1154 &bp->r[chip]->r[CD180_CCR]);
1155 /* Setting up modem option registers */
1156 sbus_writeb(mcor1, &bp->r[chip]->r[CD180_MCOR1]);
1157 sbus_writeb(mcor2, &bp->r[chip]->r[CD180_MCOR2]);
1158 /* Enable CD180 transmitter & receiver */
1159 aurora_wait_CCR(bp->r[chip]);
1160 sbus_writeb(CCR_TXEN | CCR_RXEN, &bp->r[chip]->r[CD180_CCR]);
1161 /* Enable interrupts */
1162 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1163 /* And finally set RTS on */
1164 sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
1166 printk("aurora_change_speed: end\n");
1170 /* Must be called with interrupts enabled */
1171 static int aurora_setup_port(struct Aurora_board *bp, struct Aurora_port *port)
1173 unsigned long flags;
1176 printk("aurora_setup_port: start %d\n",port_No(port));
1178 if (port->flags & ASYNC_INITIALIZED)
1181 if (!port->xmit_buf) {
1182 /* We may sleep in get_zeroed_page() */
1185 if (!(tmp = get_zeroed_page(GFP_KERNEL)))
1188 if (port->xmit_buf) {
1190 return -ERESTARTSYS;
1192 port->xmit_buf = (unsigned char *) tmp;
1195 save_flags(flags); cli();
1198 clear_bit(TTY_IO_ERROR, &port->tty->flags);
1201 if ((port->count == 1) && ((++bp->count) == 1))
1202 bp->flags |= AURORA_BOARD_ACTIVE;
1205 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1206 aurora_change_speed(bp, port);
1207 port->flags |= ASYNC_INITIALIZED;
1209 restore_flags(flags);
1211 printk("aurora_setup_port: end\n");
1216 /* Must be called with interrupts disabled */
1217 static void aurora_shutdown_port(struct Aurora_board *bp, struct Aurora_port *port)
1219 struct tty_struct *tty;
1223 printk("aurora_shutdown_port: start\n");
1225 if (!(port->flags & ASYNC_INITIALIZED))
1228 chip = AURORA_CD180(port_No(port));
1230 #ifdef AURORA_REPORT_OVERRUN
1231 printk("aurora%d: port %d: Total %ld overruns were detected.\n",
1232 board_No(bp), port_No(port), port->overrun);
1234 #ifdef AURORA_REPORT_FIFO
1238 printk("aurora%d: port %d: FIFO hits [ ",
1239 board_No(bp), port_No(port));
1240 for (i = 0; i < 10; i++) {
1241 printk("%ld ", port->hits[i]);
1246 if (port->xmit_buf) {
1247 free_page((unsigned long) port->xmit_buf);
1248 port->xmit_buf = NULL;
1251 if (!(tty = port->tty) || C_HUPCL(tty)) {
1253 port->MSVR &= ~(bp->DTR|bp->RTS);
1254 sbus_writeb(port->MSVR,
1255 &bp->r[chip]->r[CD180_MSVR]);
1259 sbus_writeb(port_No(port) & 7,
1260 &bp->r[chip]->r[CD180_CAR]);
1264 aurora_wait_CCR(bp->r[chip]);
1265 sbus_writeb(CCR_SOFTRESET, &bp->r[chip]->r[CD180_CCR]);
1267 /* Disable all interrupts from this port */
1269 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1272 set_bit(TTY_IO_ERROR, &tty->flags);
1273 port->flags &= ~ASYNC_INITIALIZED;
1276 if (--bp->count < 0) {
1277 printk(KERN_DEBUG "aurora%d: aurora_shutdown_port: "
1278 "bad board count: %d\n",
1279 board_No(bp), bp->count);
1284 bp->flags &= ~AURORA_BOARD_ACTIVE;
1288 printk("aurora_shutdown_port: end\n");
1293 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1294 struct Aurora_port *port)
1296 DECLARE_WAITQUEUE(wait, current);
1297 struct Aurora_board *bp = port_Board(port);
1304 printk("block_til_ready: start\n");
1306 chip = AURORA_CD180(port_No(port));
1308 /* If the device is in the middle of being closed, then block
1309 * until it's done, and then try again.
1311 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
1312 interruptible_sleep_on(&port->close_wait);
1313 if (port->flags & ASYNC_HUP_NOTIFY)
1316 return -ERESTARTSYS;
1319 /* If non-blocking mode is set, or the port is not enabled,
1320 * then make the check up front and then exit.
1322 if ((filp->f_flags & O_NONBLOCK) ||
1323 (tty->flags & (1 << TTY_IO_ERROR))) {
1324 port->flags |= ASYNC_NORMAL_ACTIVE;
1331 /* Block waiting for the carrier detect and the line to become
1332 * free (i.e., not in use by the callout). While we are in
1333 * this loop, info->count is dropped by one, so that
1334 * rs_close() knows when to free things. We restore it upon
1335 * exit, either normal or abnormal.
1338 add_wait_queue(&port->open_wait, &wait);
1340 if (!tty_hung_up_p(filp))
1343 port->blocked_open++;
1346 sbus_writeb(port_No(port) & 7,
1347 &bp->r[chip]->r[CD180_CAR]);
1349 CD = sbus_readb(&bp->r[chip]->r[CD180_MSVR]) & MSVR_CD;
1352 /* auto drops DTR */
1353 sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
1355 set_current_state(TASK_INTERRUPTIBLE);
1356 if (tty_hung_up_p(filp) ||
1357 !(port->flags & ASYNC_INITIALIZED)) {
1358 if (port->flags & ASYNC_HUP_NOTIFY)
1361 retval = -ERESTARTSYS;
1364 if (!(port->flags & ASYNC_CLOSING) &&
1367 if (signal_pending(current)) {
1368 retval = -ERESTARTSYS;
1373 current->state = TASK_RUNNING;
1374 remove_wait_queue(&port->open_wait, &wait);
1375 if (!tty_hung_up_p(filp))
1377 port->blocked_open--;
1381 port->flags |= ASYNC_NORMAL_ACTIVE;
1383 printk("block_til_ready: end\n");
1388 static int aurora_open(struct tty_struct * tty, struct file * filp)
1392 struct Aurora_port * port;
1393 struct Aurora_board * bp;
1394 unsigned long flags;
1397 printk("aurora_open: start\n");
1400 board = AURORA_BOARD(tty->index);
1401 if (board > AURORA_NBOARD ||
1402 !(aurora_board[board].flags & AURORA_BOARD_PRESENT)) {
1404 printk("aurora_open: error board %d present %d\n",
1405 board, aurora_board[board].flags & AURORA_BOARD_PRESENT);
1410 bp = &aurora_board[board];
1411 port = aurora_port + board * AURORA_NPORT * AURORA_NCD180 + AURORA_PORT(tty->index);
1412 if ((aurora_paranoia_check(port, tty->name, "aurora_open")) {
1414 printk("aurora_open: error paranoia check\n");
1420 tty->driver_data = port;
1423 if ((error = aurora_setup_port(bp, port))) {
1425 printk("aurora_open: error aurora_setup_port ret %d\n",error);
1430 if ((error = block_til_ready(tty, filp, port))) {
1432 printk("aurora_open: error block_til_ready ret %d\n",error);
1438 printk("aurora_open: end\n");
1443 static void aurora_close(struct tty_struct * tty, struct file * filp)
1445 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1446 struct Aurora_board *bp;
1447 unsigned long flags;
1448 unsigned long timeout;
1452 printk("aurora_close: start\n");
1455 if (!port || (aurora_paranoia_check(port, tty->name, "close"))
1458 chip = AURORA_CD180(port_No(port));
1460 save_flags(flags); cli();
1461 if (tty_hung_up_p(filp)) {
1462 restore_flags(flags);
1466 bp = port_Board(port);
1467 if ((tty->count == 1) && (port->count != 1)) {
1468 printk(KERN_DEBUG "aurora%d: aurora_close: bad port count; "
1469 "tty->count is 1, port count is %d\n",
1470 board_No(bp), port->count);
1473 if (--port->count < 0) {
1474 printk(KERN_DEBUG "aurora%d: aurora_close: bad port "
1475 "count for tty%d: %d\n",
1476 board_No(bp), port_No(port), port->count);
1480 restore_flags(flags);
1483 port->flags |= ASYNC_CLOSING;
1485 /* Now we wait for the transmit buffer to clear; and we notify
1486 * the line discipline to only process XON/XOFF characters.
1489 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE){
1491 printk("aurora_close: waiting to flush...\n");
1493 tty_wait_until_sent(tty, port->closing_wait);
1496 /* At this point we stop accepting input. To do this, we
1497 * disable the receive line status interrupts, and tell the
1498 * interrupt driver to stop checking the data ready bit in the
1499 * line status register.
1501 port->SRER &= ~SRER_RXD;
1502 if (port->flags & ASYNC_INITIALIZED) {
1503 port->SRER &= ~SRER_TXRDY;
1504 port->SRER |= SRER_TXEMPTY;
1505 sbus_writeb(port_No(port) & 7,
1506 &bp->r[chip]->r[CD180_CAR]);
1508 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1510 * Before we drop DTR, make sure the UART transmitter
1511 * has completely drained; this is especially
1512 * important if there is a transmit FIFO!
1514 timeout = jiffies+HZ;
1515 while(port->SRER & SRER_TXEMPTY) {
1516 msleep_interruptible(jiffies_to_msecs(port->timeout));
1517 if (time_after(jiffies, timeout))
1522 printk("aurora_close: shutdown_port\n");
1524 aurora_shutdown_port(bp, port);
1525 if (tty->driver->flush_buffer)
1526 tty->driver->flush_buffer(tty);
1527 tty_ldisc_flush(tty);
1531 if (port->blocked_open) {
1532 if (port->close_delay) {
1533 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1535 wake_up_interruptible(&port->open_wait);
1537 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1538 wake_up_interruptible(&port->close_wait);
1539 restore_flags(flags);
1541 printk("aurora_close: end\n");
1545 static int aurora_write(struct tty_struct * tty,
1546 const unsigned char *buf, int count)
1548 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1549 struct Aurora_board *bp;
1551 unsigned long flags;
1555 printk("aurora_write: start %d\n",count);
1557 if ((aurora_paranoia_check(port, tty->name, "aurora_write"))
1560 chip = AURORA_CD180(port_No(port));
1562 bp = port_Board(port);
1564 if (!tty || !port->xmit_buf || !tmp_buf)
1570 c = min(count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
1571 SERIAL_XMIT_SIZE - port->xmit_head));
1573 restore_flags(flags);
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);
1587 if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1588 !(port->SRER & SRER_TXRDY)) {
1589 port->SRER |= SRER_TXRDY;
1590 sbus_writeb(port_No(port) & 7,
1591 &bp->r[chip]->r[CD180_CAR]);
1593 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1595 restore_flags(flags);
1597 printk("aurora_write: end %d\n",total);
1602 static void aurora_put_char(struct tty_struct * tty, unsigned char ch)
1604 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1605 unsigned long flags;
1608 printk("aurora_put_char: start %c\n",ch);
1610 if ((aurora_paranoia_check(port, tty->name, "aurora_put_char"))
1613 if (!tty || !port->xmit_buf)
1616 save_flags(flags); cli();
1618 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
1619 restore_flags(flags);
1623 port->xmit_buf[port->xmit_head++] = ch;
1624 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1626 restore_flags(flags);
1628 printk("aurora_put_char: end\n");
1632 static void aurora_flush_chars(struct tty_struct * tty)
1634 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1635 unsigned long flags;
1638 /*#ifdef AURORA_DEBUG
1639 printk("aurora_flush_chars: start\n");
1641 if ((aurora_paranoia_check(port, tty->name, "aurora_flush_chars"))
1644 chip = AURORA_CD180(port_No(port));
1646 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1650 save_flags(flags); cli();
1651 port->SRER |= SRER_TXRDY;
1652 sbus_writeb(port_No(port) & 7,
1653 &port_Board(port)->r[chip]->r[CD180_CAR]);
1655 sbus_writeb(port->SRER,
1656 &port_Board(port)->r[chip]->r[CD180_SRER]);
1657 restore_flags(flags);
1658 /*#ifdef AURORA_DEBUG
1659 printk("aurora_flush_chars: end\n");
1663 static int aurora_write_room(struct tty_struct * tty)
1665 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1669 printk("aurora_write_room: start\n");
1671 if ((aurora_paranoia_check(port, tty->name, "aurora_write_room"))
1674 ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
1678 printk("aurora_write_room: end\n");
1683 static int aurora_chars_in_buffer(struct tty_struct *tty)
1685 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1687 if ((aurora_paranoia_check(port, tty->name, "aurora_chars_in_buffer"))
1690 return port->xmit_cnt;
1693 static void aurora_flush_buffer(struct tty_struct *tty)
1695 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1696 unsigned long flags;
1699 printk("aurora_flush_buffer: start\n");
1701 if ((aurora_paranoia_check(port, tty->name, "aurora_flush_buffer"))
1704 save_flags(flags); cli();
1705 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1706 restore_flags(flags);
1710 printk("aurora_flush_buffer: end\n");
1714 static int aurora_tiocmget(struct tty_struct *tty, struct file *file)
1716 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1717 struct Aurora_board * bp;
1718 unsigned char status,chip;
1719 unsigned int result;
1720 unsigned long flags;
1723 printk("aurora_get_modem_info: start\n");
1725 if ((aurora_paranoia_check(port, tty->name, __FUNCTION__))
1728 chip = AURORA_CD180(port_No(port));
1730 bp = port_Board(port);
1732 save_flags(flags); cli();
1734 sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1737 status = sbus_readb(&bp->r[chip]->r[CD180_MSVR]);
1738 result = 0/*bp->r[chip]->r[AURORA_RI] & (1u << port_No(port)) ? 0 : TIOCM_RNG*/;
1740 restore_flags(flags);
1742 result |= ((status & bp->RTS) ? TIOCM_RTS : 0)
1743 | ((status & bp->DTR) ? TIOCM_DTR : 0)
1744 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1745 | ((status & MSVR_DSR) ? TIOCM_DSR : 0)
1746 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1749 printk("aurora_get_modem_info: end\n");
1754 static int aurora_tiocmset(struct tty_struct *tty, struct file *file,
1755 unsigned int set, unsigned int clear)
1757 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1759 unsigned long flags;
1760 struct Aurora_board *bp = port_Board(port);
1764 printk("aurora_set_modem_info: start\n");
1766 if ((aurora_paranoia_check(port, tty->name, __FUNCTION__))
1769 chip = AURORA_CD180(port_No(port));
1771 save_flags(flags); cli();
1772 if (set & TIOCM_RTS)
1773 port->MSVR |= bp->RTS;
1774 if (set & TIOCM_DTR)
1775 port->MSVR |= bp->DTR;
1776 if (clear & TIOCM_RTS)
1777 port->MSVR &= ~bp->RTS;
1778 if (clear & TIOCM_DTR)
1779 port->MSVR &= ~bp->DTR;
1781 sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1784 sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
1786 restore_flags(flags);
1788 printk("aurora_set_modem_info: end\n");
1793 static void aurora_send_break(struct Aurora_port * port, unsigned long length)
1795 struct Aurora_board *bp = port_Board(port);
1796 unsigned long flags;
1800 printk("aurora_send_break: start\n");
1802 chip = AURORA_CD180(port_No(port));
1804 save_flags(flags); cli();
1806 port->break_length = AURORA_TPS / HZ * length;
1807 port->COR2 |= COR2_ETC;
1808 port->SRER |= SRER_TXRDY;
1809 sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1812 sbus_writeb(port->COR2, &bp->r[chip]->r[CD180_COR2]);
1813 sbus_writeb(port->SRER, &bp->r[chip]->r[CD180_SRER]);
1814 aurora_wait_CCR(bp->r[chip]);
1816 sbus_writeb(CCR_CORCHG2, &bp->r[chip]->r[CD180_CCR]);
1817 aurora_wait_CCR(bp->r[chip]);
1819 restore_flags(flags);
1821 printk("aurora_send_break: end\n");
1825 static int aurora_set_serial_info(struct Aurora_port * port,
1826 struct serial_struct * newinfo)
1828 struct serial_struct tmp;
1829 struct Aurora_board *bp = port_Board(port);
1831 unsigned long flags;
1834 printk("aurora_set_serial_info: start\n");
1836 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
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))
1849 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1850 (tmp.flags & ASYNC_SPD_MASK));
1852 if (!capable(CAP_SYS_ADMIN)) {
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)))
1858 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1859 (tmp.flags & ASYNC_USR_MASK));
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;
1867 save_flags(flags); cli();
1868 aurora_change_speed(bp, port);
1869 restore_flags(flags);
1872 printk("aurora_set_serial_info: end\n");
1877 extern 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);
1884 printk("aurora_get_serial_info: start\n");
1886 if (!access_ok(VERIFY_WRITE, (void *) retinfo, sizeof(tmp)))
1889 memset(&tmp, 0, sizeof(tmp));
1890 tmp.type = PORT_CIRRUS;
1891 tmp.line = port - aurora_port;
1894 tmp.flags = port->flags;
1895 tmp.baud_base = (bp->oscfreq + CD180_TPC/2) / CD180_TPC;
1896 tmp.close_delay = port->close_delay * HZ/100;
1897 tmp.closing_wait = port->closing_wait * HZ/100;
1898 tmp.xmit_fifo_size = CD180_NFIFO;
1899 copy_to_user(retinfo, &tmp, sizeof(tmp));
1901 printk("aurora_get_serial_info: end\n");
1906 static int aurora_ioctl(struct tty_struct * tty, struct file * filp,
1907 unsigned int cmd, unsigned long arg)
1910 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1914 printk("aurora_ioctl: start\n");
1916 if ((aurora_paranoia_check(port, tty->name, "aurora_ioctl"))
1920 case TCSBRK: /* SVID version: non-zero arg --> no break */
1921 retval = tty_check_change(tty);
1924 tty_wait_until_sent(tty, 0);
1926 aurora_send_break(port, HZ/4); /* 1/4 second */
1928 case TCSBRKP: /* support for POSIX tcsendbreak() */
1929 retval = tty_check_change(tty);
1932 tty_wait_until_sent(tty, 0);
1933 aurora_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1936 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *)arg);
1938 if (get_user(arg,(unsigned long *)arg))
1940 tty->termios->c_cflag =
1941 ((tty->termios->c_cflag & ~CLOCAL) |
1942 (arg ? CLOCAL : 0));
1945 return aurora_get_serial_info(port, (struct serial_struct *) arg);
1947 return aurora_set_serial_info(port, (struct serial_struct *) arg);
1949 return -ENOIOCTLCMD;
1952 printk("aurora_ioctl: end\n");
1957 static void aurora_throttle(struct tty_struct * tty)
1959 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1960 struct Aurora_board *bp;
1961 unsigned long flags;
1965 printk("aurora_throttle: start\n");
1967 if ((aurora_paranoia_check(port, tty->name, "aurora_throttle"))
1970 bp = port_Board(port);
1971 chip = AURORA_CD180(port_No(port));
1973 save_flags(flags); cli();
1974 port->MSVR &= ~bp->RTS;
1975 sbus_writeb(port_No(port) & 7, &bp->r[chip]->r[CD180_CAR]);
1978 aurora_wait_CCR(bp->r[chip]);
1979 sbus_writeb(CCR_SSCH2, &bp->r[chip]->r[CD180_CCR]);
1980 aurora_wait_CCR(bp->r[chip]);
1982 sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
1983 restore_flags(flags);
1985 printk("aurora_throttle: end\n");
1989 static void aurora_unthrottle(struct tty_struct * tty)
1991 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
1992 struct Aurora_board *bp;
1993 unsigned long flags;
1997 printk("aurora_unthrottle: start\n");
1999 if ((aurora_paranoia_check(port, tty->name, "aurora_unthrottle"))
2002 bp = port_Board(port);
2004 chip = AURORA_CD180(port_No(port));
2006 save_flags(flags); cli();
2007 port->MSVR |= bp->RTS;
2008 sbus_writeb(port_No(port) & 7,
2009 &bp->r[chip]->r[CD180_CAR]);
2012 aurora_wait_CCR(bp->r[chip]);
2013 sbus_writeb(CCR_SSCH1,
2014 &bp->r[chip]->r[CD180_CCR]);
2015 aurora_wait_CCR(bp->r[chip]);
2017 sbus_writeb(port->MSVR, &bp->r[chip]->r[CD180_MSVR]);
2018 restore_flags(flags);
2020 printk("aurora_unthrottle: end\n");
2024 static void aurora_stop(struct tty_struct * tty)
2026 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2027 struct Aurora_board *bp;
2028 unsigned long flags;
2032 printk("aurora_stop: start\n");
2034 if ((aurora_paranoia_check(port, tty->name, "aurora_stop"))
2037 bp = port_Board(port);
2039 chip = AURORA_CD180(port_No(port));
2041 save_flags(flags); cli();
2042 port->SRER &= ~SRER_TXRDY;
2043 sbus_writeb(port_No(port) & 7,
2044 &bp->r[chip]->r[CD180_CAR]);
2046 sbus_writeb(port->SRER,
2047 &bp->r[chip]->r[CD180_SRER]);
2048 restore_flags(flags);
2050 printk("aurora_stop: end\n");
2054 static void aurora_start(struct tty_struct * tty)
2056 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2057 struct Aurora_board *bp;
2058 unsigned long flags;
2062 printk("aurora_start: start\n");
2064 if ((aurora_paranoia_check(port, tty->name, "aurora_start"))
2067 bp = port_Board(port);
2069 chip = AURORA_CD180(port_No(port));
2071 save_flags(flags); cli();
2072 if (port->xmit_cnt && port->xmit_buf && !(port->SRER & SRER_TXRDY)) {
2073 port->SRER |= SRER_TXRDY;
2074 sbus_writeb(port_No(port) & 7,
2075 &bp->r[chip]->r[CD180_CAR]);
2077 sbus_writeb(port->SRER,
2078 &bp->r[chip]->r[CD180_SRER]);
2080 restore_flags(flags);
2082 printk("aurora_start: end\n");
2087 * This routine is called from the scheduler tqueue when the interrupt
2088 * routine has signalled that a hangup has occurred. The path of
2089 * hangup processing is:
2091 * serial interrupt routine -> (scheduler tqueue) ->
2092 * do_aurora_hangup() -> tty->hangup() -> aurora_hangup()
2095 static void do_aurora_hangup(void *private_)
2097 struct Aurora_port *port = (struct Aurora_port *) private_;
2098 struct tty_struct *tty;
2101 printk("do_aurora_hangup: start\n");
2105 tty_hangup(tty); /* FIXME: module removal race - AKPM */
2107 printk("do_aurora_hangup: end\n");
2112 static void aurora_hangup(struct tty_struct * tty)
2114 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2115 struct Aurora_board *bp;
2118 printk("aurora_hangup: start\n");
2120 if ((aurora_paranoia_check(port, tty->name, "aurora_hangup"))
2123 bp = port_Board(port);
2125 aurora_shutdown_port(bp, port);
2128 port->flags &= ~ASYNC_NORMAL_ACTIVE;
2130 wake_up_interruptible(&port->open_wait);
2132 printk("aurora_hangup: end\n");
2136 static void aurora_set_termios(struct tty_struct * tty, struct termios * old_termios)
2138 struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
2139 unsigned long flags;
2142 printk("aurora_set_termios: start\n");
2144 if ((aurora_paranoia_check(port, tty->name, "aurora_set_termios"))
2147 if (tty->termios->c_cflag == old_termios->c_cflag &&
2148 tty->termios->c_iflag == old_termios->c_iflag)
2151 save_flags(flags); cli();
2152 aurora_change_speed(port_Board(port), port);
2153 restore_flags(flags);
2155 if ((old_termios->c_cflag & CRTSCTS) &&
2156 !(tty->termios->c_cflag & CRTSCTS)) {
2157 tty->hw_stopped = 0;
2161 printk("aurora_set_termios: end\n");
2165 static void do_aurora_bh(void)
2167 run_task_queue(&tq_aurora);
2170 static void do_softint(void *private_)
2172 struct Aurora_port *port = (struct Aurora_port *) private_;
2173 struct tty_struct *tty;
2176 printk("do_softint: start\n");
2182 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) {
2186 printk("do_softint: end\n");
2190 static struct tty_operations aurora_ops = {
2191 .open = aurora_open,
2192 .close = aurora_close,
2193 .write = aurora_write,
2194 .put_char = aurora_put_char,
2195 .flush_chars = aurora_flush_chars,
2196 .write_room = aurora_write_room,
2197 .chars_in_buffer = aurora_chars_in_buffer,
2198 .flush_buffer = aurora_flush_buffer,
2199 .ioctl = aurora_ioctl,
2200 .throttle = aurora_throttle,
2201 .unthrottle = aurora_unthrottle,
2202 .set_termios = aurora_set_termios,
2203 .stop = aurora_stop,
2204 .start = aurora_start,
2205 .hangup = aurora_hangup,
2206 .tiocmget = aurora_tiocmget,
2207 .tiocmset = aurora_tiocmset,
2210 static int aurora_init_drivers(void)
2216 printk("aurora_init_drivers: start\n");
2218 tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
2219 if (tmp_buf == NULL) {
2220 printk(KERN_ERR "aurora: Couldn't get free page.\n");
2223 init_bh(AURORA_BH, do_aurora_bh);
2224 aurora_driver = alloc_tty_driver(AURORA_INPORTS);
2225 if (!aurora_driver) {
2226 printk(KERN_ERR "aurora: Couldn't allocate tty driver.\n");
2227 free_page((unsigned long) tmp_buf);
2230 aurora_driver->owner = THIS_MODULE;
2231 aurora_driver->name = "ttyA";
2232 aurora_driver->major = AURORA_MAJOR;
2233 aurora_driver->type = TTY_DRIVER_TYPE_SERIAL;
2234 aurora_driver->subtype = SERIAL_TYPE_NORMAL;
2235 aurora_driver->init_termios = tty_std_termios;
2236 aurora_driver->init_termios.c_cflag =
2237 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2238 aurora_driver->flags = TTY_DRIVER_REAL_RAW;
2239 tty_set_operations(aurora_driver, &aurora_ops);
2240 error = tty_register_driver(aurora_driver);
2242 put_tty_driver(aurora_driver);
2243 free_page((unsigned long) tmp_buf);
2244 printk(KERN_ERR "aurora: Couldn't register aurora driver, error = %d\n",
2249 memset(aurora_port, 0, sizeof(aurora_port));
2250 for (i = 0; i < AURORA_TNPORTS; i++) {
2251 aurora_port[i].magic = AURORA_MAGIC;
2252 aurora_port[i].tqueue.routine = do_softint;
2253 aurora_port[i].tqueue.data = &aurora_port[i];
2254 aurora_port[i].tqueue_hangup.routine = do_aurora_hangup;
2255 aurora_port[i].tqueue_hangup.data = &aurora_port[i];
2256 aurora_port[i].close_delay = 50 * HZ/100;
2257 aurora_port[i].closing_wait = 3000 * HZ/100;
2258 init_waitqueue_head(&aurora_port[i].open_wait);
2259 init_waitqueue_head(&aurora_port[i].close_wait);
2262 printk("aurora_init_drivers: end\n");
2267 static void aurora_release_drivers(void)
2270 printk("aurora_release_drivers: start\n");
2272 free_page((unsigned long)tmp_buf);
2273 tty_unregister_driver(aurora_driver);
2274 put_tty_driver(aurora_driver);
2276 printk("aurora_release_drivers: end\n");
2281 * Called at boot time.
2283 * You can specify IO base for up to RC_NBOARD cards,
2284 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
2285 * Note that there will be no probing at default
2286 * addresses in this case.
2289 void __init aurora_setup(char *str, int *ints)
2293 for(i=0;(i<ints[0])&&(i<4);i++) {
2294 if (ints[i+1]) irqs[i]=ints[i+1];
2298 static int __init aurora_real_init(void)
2303 printk(KERN_INFO "aurora: Driver starting.\n");
2304 if(aurora_init_drivers())
2306 found = aurora_probe();
2308 aurora_release_drivers();
2309 printk(KERN_INFO "aurora: No Aurora Multiport boards detected.\n");
2312 printk(KERN_INFO "aurora: %d boards found.\n", found);
2314 for (i = 0; i < found; i++) {
2315 int ret = aurora_setup_board(&aurora_board[i]);
2319 printk(KERN_ERR "aurora_init: error aurora_setup_board ret %d\n",
2332 module_param(irq , int, 0);
2333 module_param(irq1, int, 0);
2334 module_param(irq2, int, 0);
2335 module_param(irq3, int, 0);
2337 static int __init aurora_init(void)
2339 if (irq ) irqs[0]=irq ;
2340 if (irq1) irqs[1]=irq1;
2341 if (irq2) irqs[2]=irq2;
2342 if (irq3) irqs[3]=irq3;
2343 return aurora_real_init();
2346 static void __exit aurora_cleanup(void)
2351 printk("cleanup_module: aurora_release_drivers\n");
2354 aurora_release_drivers();
2355 for (i = 0; i < AURORA_NBOARD; i++)
2356 if (aurora_board[i].flags & AURORA_BOARD_PRESENT) {
2357 aurora_shutdown_board(&aurora_board[i]);
2358 aurora_release_io_range(&aurora_board[i]);
2362 module_init(aurora_init);
2363 module_exit(aurora_cleanup);
2364 MODULE_LICENSE("GPL");