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