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