This source file includes following definitions.
- init_module
- cleanup_module
- stl_memalloc
- stl_open
- stl_waitcarrier
- stl_close
- stl_delay
- stl_write
- stl_putchar
- stl_flushchars
- stl_writeroom
- stl_charsinbuffer
- stl_getserial
- stl_setserial
- stl_ioctl
- stl_settermios
- stl_throttle
- stl_unthrottle
- stl_stop
- stl_start
- stl_hangup
- stl_flushbuffer
- stl_getreg
- stl_setreg
- stl_updatereg
- stl_txisr
- stl_rxisr
- stl_mdmisr
- stl_intr
- stl_offintr
- stl_ccrwait
- stl_setport
- stl_setsignals
- stl_getsignals
- stl_enablerxtx
- stl_startrxtx
- stl_disableintrs
- stl_sendbreak
- stl_mapirq
- stl_initports
- stl_initeio
- stl_initech
- stl_brdinit
- stl_findpcibrds
- stl_initbrds
- stl_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 #ifdef MODULE
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/version.h>
32 #endif
33
34 #include <linux/errno.h>
35 #include <linux/sched.h>
36 #include <linux/wait.h>
37 #include <linux/interrupt.h>
38 #include <linux/termios.h>
39 #include <linux/fcntl.h>
40 #include <linux/tty_driver.h>
41 #include <linux/tty.h>
42 #include <linux/tty_flip.h>
43 #include <linux/serial.h>
44 #include <linux/cd1400.h>
45 #include <linux/string.h>
46 #include <linux/malloc.h>
47 #include <linux/ioport.h>
48 #include <asm/system.h>
49 #include <asm/io.h>
50 #include <asm/segment.h>
51
52 #ifdef CONFIG_PCI
53 #include <linux/pci.h>
54 #include <linux/bios32.h>
55 #endif
56
57
58
59
60
61
62
63
64
65
66 #define BRD_EASYIO 20
67 #define BRD_ECH 21
68 #define BRD_ECHMC 22
69 #define BRD_ECHPCI 26
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 typedef struct {
97 int brdtype;
98 int ioaddr1;
99 int ioaddr2;
100 unsigned long memaddr;
101 int irq;
102 int irqtype;
103 } stlconf_t;
104
105 static stlconf_t stl_brdconf[] = {
106 { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
107 };
108
109 static int stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
110
111
112
113
114
115
116
117 #ifndef STL_SERIALMAJOR
118 #define STL_SERIALMAJOR 24
119 #endif
120 #ifndef STL_CALLOUTMAJOR
121 #define STL_CALLOUTMAJOR 25
122 #endif
123
124 #define STL_DRVTYPSERIAL 1
125 #define STL_DRVTYPCALLOUT 2
126
127 #define STL_MAXBRDS 4
128 #define STL_MAXPANELS 4
129 #define STL_PORTSPERPANEL 16
130 #define STL_MAXPORTS 64
131 #define STL_MAXDEVS (STL_MAXBRDS * STL_MAXPORTS)
132
133
134
135
136
137
138 #define STL_TXBUFLOW 256
139 #define STL_TXBUFSIZE 2048
140
141
142
143
144
145
146
147 static char *stl_drvname = "Stallion Multiport Serial Driver";
148 static char *stl_drvversion = "1.0.0";
149 static char *stl_serialname = "ttyE";
150 static char *stl_calloutname = "cue";
151
152 static struct tty_driver stl_serial;
153 static struct tty_driver stl_callout;
154 static struct tty_struct *stl_ttys[STL_MAXDEVS];
155 static struct termios *stl_termios[STL_MAXDEVS];
156 static struct termios *stl_termioslocked[STL_MAXDEVS];
157 static int stl_refcount = 0;
158
159
160
161
162
163
164
165
166 static char *stl_tmpwritebuf;
167 static struct semaphore stl_tmpwritesem = MUTEX;
168
169
170
171
172
173
174 static struct termios stl_deftermios = {
175 0,
176 0,
177 (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
178 0,
179 0,
180 INIT_C_CC
181 };
182
183
184
185
186
187
188 static int stl_gotintrs[STL_MAXBRDS];
189 static int stl_numintrs = 0;
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208 typedef struct {
209 char *buf;
210 char *head;
211 char *tail;
212 } stlrq_t;
213
214
215
216
217
218
219
220
221
222
223 typedef struct {
224 int portnr;
225 int panelnr;
226 int brdnr;
227 int ioaddr;
228 int uartaddr;
229 int pagenr;
230 int istate;
231 int flags;
232 int baud_base;
233 int custom_divisor;
234 int close_delay;
235 int closing_wait;
236 int refcount;
237 int openwaitcnt;
238 int brklen;
239 long session;
240 long pgrp;
241 unsigned int sigs;
242 unsigned int rxignoremsk;
243 unsigned int rxmarkmsk;
244 struct tty_struct *tty;
245 struct wait_queue *open_wait;
246 struct wait_queue *close_wait;
247 struct termios normaltermios;
248 struct termios callouttermios;
249 struct tq_struct tqueue;
250 stlrq_t tx;
251 } stlport_t;
252
253 typedef struct {
254 int panelnr;
255 int brdnr;
256 int pagenr;
257 int nrports;
258 int iobase;
259 unsigned int ackmask;
260 stlport_t *ports[STL_PORTSPERPANEL];
261 } stlpanel_t;
262
263 typedef struct {
264 int brdnr;
265 int brdtype;
266 int state;
267 int nrpanels;
268 int nrports;
269 int irq;
270 int irqtype;
271 unsigned int ioaddr1;
272 unsigned int ioaddr2;
273 unsigned int iostatus;
274 unsigned int ioctrl;
275 unsigned int ioctrlval;
276 stlpanel_t *panels[STL_MAXPANELS];
277 } stlbrd_t;
278
279 static stlbrd_t *stl_brds[STL_MAXBRDS];
280
281
282
283
284
285 #define BRD_FOUND 0x1
286
287
288
289
290
291
292 #define ASYI_TXBUSY 1
293 #define ASYI_TXLOW 2
294 #define ASYI_DCDCHANGE 3
295
296
297
298
299
300 static char *stl_brdnames[] = {
301 (char *) NULL,
302 (char *) NULL,
303 (char *) NULL,
304 (char *) NULL,
305 (char *) NULL,
306 (char *) NULL,
307 (char *) NULL,
308 (char *) NULL,
309 (char *) NULL,
310 (char *) NULL,
311 (char *) NULL,
312 (char *) NULL,
313 (char *) NULL,
314 (char *) NULL,
315 (char *) NULL,
316 (char *) NULL,
317 (char *) NULL,
318 (char *) NULL,
319 (char *) NULL,
320 (char *) NULL,
321 "EasyIO",
322 "EC8/32-AT",
323 "EC8/32-MC",
324 (char *) NULL,
325 (char *) NULL,
326 (char *) NULL,
327 "EC8/32-PCI",
328 };
329
330
331
332
333
334
335
336
337 #define EIO_8PORTRS 0x04
338 #define EIO_4PORTRS 0x05
339 #define EIO_8PORTDI 0x00
340 #define EIO_8PORTM 0x06
341 #define EIO_IDBITMASK 0x07
342 #define EIO_INTRPEND 0x08
343 #define EIO_INTEDGE 0x00
344 #define EIO_INTLEVEL 0x08
345
346 #define ECH_ID 0xa0
347 #define ECH_IDBITMASK 0xe0
348 #define ECH_BRDENABLE 0x08
349 #define ECH_BRDDISABLE 0x00
350 #define ECH_INTENABLE 0x01
351 #define ECH_INTDISABLE 0x00
352 #define ECH_INTLEVEL 0x02
353 #define ECH_INTEDGE 0x00
354 #define ECH_INTRPEND 0x01
355 #define ECH_BRDRESET 0x01
356
357 #define ECHMC_INTENABLE 0x01
358 #define ECHMC_BRDRESET 0x02
359
360 #define ECH_PNLSTATUS 2
361 #define ECH_PNL16PORT 0x20
362 #define ECH_PNLIDMASK 0x07
363 #define ECH_PNLINTRPEND 0x80
364 #define ECH_ADDR2MASK 0x1e0
365
366
367
368
369
370 #define EREG_ADDR 0
371 #define EREG_DATA 4
372 #define EREG_RXACK 5
373 #define EREG_TXACK 6
374 #define EREG_MDACK 7
375
376 #define EREG_BANKSIZE 8
377
378
379
380
381
382
383 static unsigned char stl_vecmap[] = {
384 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
385 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
386 };
387
388
389
390
391
392
393
394
395 #define BRDENABLE(brdnr,pagenr) \
396 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
397 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
398 stl_brds[(brdnr)]->ioctrl); \
399 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
400 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
401
402 #define BRDDISABLE(brdnr) \
403 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
404 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
405 stl_brds[(brdnr)]->ioctrl);
406
407
408
409
410
411
412 static int stl_cd1400clkdivs[] = {
413 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
414 };
415
416 #define STL_MAXBAUD 230400
417 #define STL_BAUDBASE 115200
418 #define STL_CLOSEDELAY 50
419
420
421
422
423
424
425 #define MKDEV2BRD(min) (((min) & 0xc0) >> 6)
426 #define MKDEV2PORT(min) ((min) & 0x3f)
427
428
429
430
431
432
433 static unsigned int stl_baudrates[] = {
434 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
435 9600, 19200, 38400, 57600, 115200, 230400
436 };
437
438
439
440
441
442
443 #ifndef MIN
444 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
445 #endif
446
447
448
449
450
451
452
453 #ifdef MODULE
454 int init_module(void);
455 void cleanup_module(void);
456 #endif
457 static void *stl_memalloc(int len);
458
459 int stl_init(void);
460 static int stl_open(struct tty_struct *tty, struct file *filp);
461 static void stl_close(struct tty_struct *tty, struct file *filp);
462 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
463 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
464 static void stl_flushchars(struct tty_struct *tty);
465 static int stl_writeroom(struct tty_struct *tty);
466 static int stl_charsinbuffer(struct tty_struct *tty);
467 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
468 static void stl_settermios(struct tty_struct *tty, struct termios *old);
469 static void stl_throttle(struct tty_struct *tty);
470 static void stl_unthrottle(struct tty_struct *tty);
471 static void stl_stop(struct tty_struct *tty);
472 static void stl_start(struct tty_struct *tty);
473 static void stl_flushbuffer(struct tty_struct *tty);
474 static void stl_hangup(struct tty_struct *tty);
475
476 static int stl_initbrds(void);
477 static int stl_brdinit(stlbrd_t *brdp);
478 static int stl_initeio(stlbrd_t *brdp);
479 static int stl_initech(stlbrd_t *brdp);
480 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
481 static int stl_mapirq(int irq);
482 static void stl_getserial(stlport_t *portp, struct serial_struct *sp);
483 static int stl_setserial(stlport_t *portp, struct serial_struct *sp);
484 static void stl_setreg(stlport_t *portp, int regnr, int value);
485 static int stl_getreg(stlport_t *portp, int regnr);
486 static int stl_updatereg(stlport_t *portp, int regnr, int value);
487 static void stl_setport(stlport_t *portp, struct termios *tiosp);
488 static void stl_getsignals(stlport_t *portp);
489 static void stl_setsignals(stlport_t *portp, int dtr, int rts);
490 static void stl_ccrwait(stlport_t *portp);
491 static void stl_enablerxtx(stlport_t *portp, int rx, int tx);
492 static void stl_startrxtx(stlport_t *portp, int rx, int tx);
493 static void stl_disableintrs(stlport_t *portp);
494 static void stl_sendbreak(stlport_t *portp, long len);
495 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
496 static void stl_delay(int len);
497 static void stl_intr(int irq, struct pt_regs *regs);
498 static void stl_offintr(void *private);
499
500 #ifdef CONFIG_PCI
501 static int stl_findpcibrds(void);
502 #endif
503
504
505
506 #ifdef MODULE
507
508
509
510
511 char kernel_version[] = UTS_RELEASE;
512
513 int init_module()
514 {
515 unsigned long flags;
516
517 #if DEBUG
518 printk("init_module()\n");
519 #endif
520
521 save_flags(flags);
522 cli();
523 stl_init();
524 restore_flags(flags);
525
526 return(0);
527 }
528
529
530
531 void cleanup_module()
532 {
533 stlbrd_t *brdp;
534 stlpanel_t *panelp;
535 stlport_t *portp;
536 unsigned long flags;
537 int i, j, k;
538
539 #if DEBUG
540 printk("cleanup_module()\n");
541 #endif
542
543 printk("Unloading %s: version %s\n", stl_drvname, stl_drvversion);
544
545 save_flags(flags);
546 cli();
547
548
549
550
551
552
553
554 i = tty_unregister_driver(&stl_serial);
555 j = tty_unregister_driver(&stl_callout);
556 if (i || j) {
557 printk("STALLION: failed to un-register tty driver, errno=%d,%d\n", -i, -j);
558 restore_flags(flags);
559 return;
560 }
561
562 if (stl_tmpwritebuf != (char *) NULL)
563 kfree_s(stl_tmpwritebuf, STL_TXBUFSIZE);
564
565 for (i = 0; (i < stl_nrbrds); i++) {
566 brdp = stl_brds[i];
567 for (j = 0; (j < STL_MAXPANELS); j++) {
568 panelp = brdp->panels[j];
569 if (panelp != (stlpanel_t *) NULL) {
570 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
571 portp = panelp->ports[k];
572 if (portp != (stlport_t *) NULL) {
573 if (portp->tty != (struct tty_struct *) NULL)
574 stl_hangup(portp->tty);
575 if (portp->tx.buf != (char *) NULL)
576 kfree_s(portp->tx.buf, STL_TXBUFSIZE);
577 kfree_s(portp, sizeof(stlport_t));
578 }
579 }
580 kfree_s(panelp, sizeof(stlpanel_t));
581 }
582
583 }
584
585 if (brdp->brdtype == BRD_ECH) {
586 release_region(brdp->ioaddr1, 2);
587 release_region(brdp->ioaddr2, 32);
588 } else if (brdp->brdtype == BRD_ECHPCI) {
589 release_region(brdp->ioaddr1, 4);
590 release_region(brdp->ioaddr2, 8);
591 } else if (brdp->brdtype == BRD_ECHMC) {
592 release_region(brdp->ioaddr1, 64);
593 } else if (brdp->brdtype == BRD_EASYIO) {
594 release_region(brdp->ioaddr1, 8);
595 }
596
597 kfree_s(brdp, sizeof(stlbrd_t));
598 stl_brds[i] = (stlbrd_t *) NULL;
599 }
600
601 for (i = 0; (i < stl_numintrs); i++)
602 free_irq(stl_gotintrs[i]);
603
604 restore_flags(flags);
605 }
606
607 #endif
608
609
610
611
612
613
614
615
616
617
618 static void *stl_memalloc(int len)
619 {
620 return (void *) kmalloc(len, GFP_KERNEL);
621 }
622
623
624
625 static int stl_open(struct tty_struct *tty, struct file *filp)
626 {
627 stlport_t *portp;
628 stlbrd_t *brdp;
629 unsigned int minordev;
630 int brdnr, panelnr, portnr, rc;
631
632 #if DEBUG
633 printk("stl_open(tty=%x,filp=%x): device=%x\n", (int) tty, (int) filp, tty->device);
634 #endif
635
636 minordev = MINOR(tty->device);
637 brdnr = MKDEV2BRD(minordev);
638 if (brdnr >= stl_nrbrds)
639 return(-ENODEV);
640 brdp = stl_brds[brdnr];
641 if (brdp == (stlbrd_t *) NULL)
642 return(-ENODEV);
643 minordev = MKDEV2PORT(minordev);
644 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
645 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
646 break;
647 if (minordev < brdp->panels[panelnr]->nrports) {
648 portnr = minordev;
649 break;
650 }
651 minordev -= brdp->panels[panelnr]->nrports;
652 }
653 if (portnr < 0)
654 return(-ENODEV);
655
656 portp = brdp->panels[panelnr]->ports[portnr];
657 if (portp == (stlport_t *) NULL)
658 return(-ENODEV);
659
660
661
662
663
664 portp->tty = tty;
665 tty->driver_data = portp;
666 portp->refcount++;
667
668 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
669 if (portp->tx.buf == (char *) NULL) {
670 portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
671 if (portp->tx.buf == (char *) NULL)
672 return(-ENOMEM);
673 portp->tx.head = portp->tx.buf;
674 portp->tx.tail = portp->tx.buf;
675 }
676 stl_setport(portp, tty->termios);
677 stl_getsignals(portp);
678 stl_setsignals(portp, 1, 1);
679 stl_enablerxtx(portp, 1, 1);
680 stl_startrxtx(portp, 1, 0);
681 clear_bit(TTY_IO_ERROR, &tty->flags);
682 portp->flags |= ASYNC_INITIALIZED;
683 }
684
685
686
687
688
689
690
691 if (portp->flags & ASYNC_CLOSING) {
692 interruptible_sleep_on(&portp->close_wait);
693 if (portp->flags & ASYNC_HUP_NOTIFY)
694 return(-EAGAIN);
695 return(-ERESTARTSYS);
696 }
697
698
699
700
701
702
703 if (tty->driver.subtype == STL_DRVTYPCALLOUT) {
704 if (portp->flags & ASYNC_NORMAL_ACTIVE)
705 return(-EBUSY);
706 if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
707 if ((portp->flags & ASYNC_SESSION_LOCKOUT) &&
708 (portp->session != current->session))
709 return(-EBUSY);
710 if ((portp->flags & ASYNC_PGRP_LOCKOUT) &&
711 (portp->pgrp != current->pgrp))
712 return(-EBUSY);
713 }
714 portp->flags |= ASYNC_CALLOUT_ACTIVE;
715 } else {
716 if (filp->f_flags & O_NONBLOCK) {
717 if (portp->flags & ASYNC_CALLOUT_ACTIVE)
718 return(-EBUSY);
719 } else {
720 if ((rc = stl_waitcarrier(portp, filp)) != 0)
721 return(rc);
722 }
723 portp->flags |= ASYNC_NORMAL_ACTIVE;
724 }
725
726 if ((portp->refcount == 1) && (portp->flags & ASYNC_SPLIT_TERMIOS)) {
727 if (tty->driver.subtype == STL_DRVTYPSERIAL)
728 *tty->termios = portp->normaltermios;
729 else
730 *tty->termios = portp->callouttermios;
731 stl_setport(portp, tty->termios);
732 }
733
734 portp->session = current->session;
735 portp->pgrp = current->pgrp;
736 return(0);
737 }
738
739
740
741
742
743
744
745
746 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
747 {
748 unsigned long flags;
749 int rc;
750
751 #if DEBUG
752 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
753 #endif
754
755 rc = 0;
756
757 save_flags(flags);
758 cli();
759 portp->openwaitcnt++;
760 if (portp->refcount > 0)
761 portp->refcount--;
762
763 for (;;) {
764 if ((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0)
765 stl_setsignals(portp, 1, 1);
766 if (tty_hung_up_p(filp) || ((portp->flags & ASYNC_INITIALIZED) == 0)) {
767 if (portp->flags & ASYNC_HUP_NOTIFY)
768 rc = -EBUSY;
769 else
770 rc = -ERESTARTSYS;
771 break;
772 }
773 if (((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) &&
774 ((portp->flags & ASYNC_CLOSING) == 0) &&
775 ((portp->tty->termios->c_cflag & CLOCAL) ||
776 (portp->sigs & TIOCM_CD))) {
777 break;
778 }
779 if (current->signal & ~current->blocked) {
780 rc = -ERESTARTSYS;
781 break;
782 }
783 interruptible_sleep_on(&portp->open_wait);
784 }
785
786 if (! tty_hung_up_p(filp))
787 portp->refcount++;
788 portp->openwaitcnt--;
789 restore_flags(flags);
790
791 return(rc);
792 }
793
794
795
796 static void stl_close(struct tty_struct *tty, struct file *filp)
797 {
798 stlport_t *portp;
799 unsigned long flags;
800
801 #if DEBUG
802 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
803 #endif
804
805 portp = tty->driver_data;
806 if (portp == (stlport_t *) NULL)
807 return;
808
809 save_flags(flags);
810 cli();
811 if (tty_hung_up_p(filp)) {
812 restore_flags(flags);
813 return;
814 }
815 if (portp->refcount-- > 1) {
816 restore_flags(flags);
817 return;
818 }
819
820 portp->refcount = 0;
821 portp->flags |= ASYNC_CLOSING;
822
823 if (portp->flags & ASYNC_NORMAL_ACTIVE)
824 portp->normaltermios = *tty->termios;
825 if (portp->flags & ASYNC_CALLOUT_ACTIVE)
826 portp->callouttermios = *tty->termios;
827
828
829
830
831
832
833 tty->closing = 1;
834 if (test_bit(ASYI_TXBUSY, &portp->istate)) {
835 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
836 tty_wait_until_sent(tty, portp->closing_wait);
837 }
838
839 portp->flags &= ~ASYNC_INITIALIZED;
840 stl_disableintrs(portp);
841 if (tty->termios->c_cflag & HUPCL)
842 stl_setsignals(portp, 0, 0);
843 stl_enablerxtx(portp, 0, 0);
844 stl_flushbuffer(tty);
845 portp->istate = 0;
846 if (portp->tx.buf != (char *) NULL) {
847 kfree_s(portp->tx.buf, STL_TXBUFSIZE);
848 portp->tx.buf = (char *) NULL;
849 portp->tx.head = (char *) NULL;
850 portp->tx.tail = (char *) NULL;
851 }
852 set_bit(TTY_IO_ERROR, &tty->flags);
853 if (tty->ldisc.flush_buffer)
854 (tty->ldisc.flush_buffer)(tty);
855
856 tty->closing = 0;
857 tty->driver_data = (void *) NULL;
858 portp->tty = (struct tty_struct *) NULL;
859
860 if (portp->openwaitcnt) {
861 if (portp->close_delay)
862 stl_delay(portp->close_delay);
863 wake_up_interruptible(&portp->open_wait);
864 }
865
866 portp->flags &= ~(ASYNC_CALLOUT_ACTIVE | ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
867 wake_up_interruptible(&portp->close_wait);
868 restore_flags(flags);
869 }
870
871
872
873
874
875
876
877
878
879 static void stl_delay(int len)
880 {
881 #if DEBUG
882 printk("stl_delay(len=%d)\n", len);
883 #endif
884 if (len > 0) {
885 current->state = TASK_INTERRUPTIBLE;
886 current->timeout = jiffies + len;
887 schedule();
888 }
889 }
890
891
892
893
894
895
896
897
898 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
899 {
900 stlport_t *portp;
901 unsigned int len, stlen;
902 unsigned long flags;
903 unsigned char *chbuf;
904 char *head, *tail;
905
906 #if DEBUG
907 printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n", (int) tty, from_user, (int) buf, count);
908 #endif
909
910 if ((tty == (struct tty_struct *) NULL) || (stl_tmpwritebuf == (char *) NULL))
911 return(0);
912 portp = tty->driver_data;
913 if (portp == (stlport_t *) NULL)
914 return(0);
915 if (portp->tx.buf == (char *) NULL)
916 return(0);
917
918
919
920
921
922
923
924 chbuf = (unsigned char *) buf;
925 if (from_user) {
926 head = portp->tx.head;
927 tail = portp->tx.tail;
928 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) :
929 (tail - head - 1);
930 count = MIN(len, count);
931
932 save_flags(flags);
933 cli();
934 down(&stl_tmpwritesem);
935 memcpy_fromfs(stl_tmpwritebuf, chbuf, count);
936 up(&stl_tmpwritesem);
937 restore_flags(flags);
938 chbuf = &stl_tmpwritebuf[0];
939 }
940
941 head = portp->tx.head;
942 tail = portp->tx.tail;
943 if (head >= tail) {
944 len = STL_TXBUFSIZE - (head - tail) - 1;
945 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
946 } else {
947 len = tail - head - 1;
948 stlen = len;
949 }
950
951 len = MIN(len, count);
952 count = 0;
953 while (len > 0) {
954 stlen = MIN(len, stlen);
955 memcpy(head, chbuf, stlen);
956 len -= stlen;
957 chbuf += stlen;
958 count += stlen;
959 head += stlen;
960 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
961 head = portp->tx.buf;
962 stlen = tail - head;
963 }
964 }
965 portp->tx.head = head;
966
967 clear_bit(ASYI_TXLOW, &portp->istate);
968 stl_startrxtx(portp, -1, 1);
969
970 return(count);
971 }
972
973
974
975 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
976 {
977 stlport_t *portp;
978 unsigned int len;
979 char *head, *tail;
980
981 #if DEBUG
982 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
983 #endif
984
985 if (tty == (struct tty_struct *) NULL)
986 return;
987 portp = tty->driver_data;
988 if (portp == (stlport_t *) NULL)
989 return;
990 if (portp->tx.buf == (char *) NULL)
991 return;
992
993 head = portp->tx.head;
994 tail = portp->tx.tail;
995
996 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
997 len--;
998
999 if (len > 0) {
1000 *head++ = ch;
1001 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1002 head = portp->tx.buf;
1003 }
1004 portp->tx.head = head;
1005 }
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015 static void stl_flushchars(struct tty_struct *tty)
1016 {
1017 stlport_t *portp;
1018
1019 #if DEBUG
1020 printk("stl_flushchars(tty=%x)\n", (int) tty);
1021 #endif
1022
1023 if (tty == (struct tty_struct *) NULL)
1024 return;
1025 portp = tty->driver_data;
1026 if (portp == (stlport_t *) NULL)
1027 return;
1028 if (portp->tx.buf == (char *) NULL)
1029 return;
1030
1031 #if 0
1032 if (tty->stopped || tty->hw_stopped || (portp->tx.head == portp->tx.tail))
1033 return;
1034 #endif
1035 stl_startrxtx(portp, -1, 1);
1036 }
1037
1038
1039
1040 static int stl_writeroom(struct tty_struct *tty)
1041 {
1042 stlport_t *portp;
1043 char *head, *tail;
1044
1045 #if DEBUG
1046 printk("stl_writeroom(tty=%x)\n", (int) tty);
1047 #endif
1048
1049 if (tty == (struct tty_struct *) NULL)
1050 return(0);
1051 portp = tty->driver_data;
1052 if (portp == (stlport_t *) NULL)
1053 return(0);
1054 if (portp->tx.buf == (char *) NULL)
1055 return(0);
1056
1057 head = portp->tx.head;
1058 tail = portp->tx.tail;
1059 return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1060 }
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073 static int stl_charsinbuffer(struct tty_struct *tty)
1074 {
1075 stlport_t *portp;
1076 unsigned int size;
1077 char *head, *tail;
1078
1079 #if DEBUG
1080 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1081 #endif
1082
1083 if (tty == (struct tty_struct *) NULL)
1084 return(0);
1085 portp = tty->driver_data;
1086 if (portp == (stlport_t *) NULL)
1087 return(0);
1088 if (portp->tx.buf == (char *) NULL)
1089 return(0);
1090
1091 head = portp->tx.head;
1092 tail = portp->tx.tail;
1093 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1094 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1095 size = 1;
1096 return(size);
1097 }
1098
1099
1100
1101
1102
1103
1104
1105 static void stl_getserial(stlport_t *portp, struct serial_struct *sp)
1106 {
1107 struct serial_struct sio;
1108 stlbrd_t *brdp;
1109
1110 #if DEBUG
1111 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1112 #endif
1113
1114 memset(&sio, 0, sizeof(struct serial_struct));
1115 sio.type = PORT_CIRRUS;
1116 sio.line = portp->portnr;
1117 sio.port = portp->ioaddr;
1118 sio.flags = portp->flags;
1119 sio.baud_base = portp->baud_base;
1120 sio.close_delay = portp->close_delay;
1121 sio.closing_wait = portp->closing_wait;
1122 sio.custom_divisor = portp->custom_divisor;
1123 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1124 sio.hub6 = 0;
1125
1126 brdp = stl_brds[portp->brdnr];
1127 if (brdp != (stlbrd_t *) NULL)
1128 sio.irq = brdp->irq;
1129
1130 memcpy_tofs(sp, &sio, sizeof(struct serial_struct));
1131 }
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141 static int stl_setserial(stlport_t *portp, struct serial_struct *sp)
1142 {
1143 struct serial_struct sio;
1144
1145 #if DEBUG
1146 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1147 #endif
1148
1149 memcpy_fromfs(&sio, sp, sizeof(struct serial_struct));
1150 if (!suser()) {
1151 if ((sio.baud_base != portp->baud_base) ||
1152 (sio.close_delay != portp->close_delay) ||
1153 ((sio.flags & ~ASYNC_USR_MASK) != (portp->flags & ~ASYNC_USR_MASK)))
1154 return(-EPERM);
1155 }
1156
1157 portp->flags = (portp->flags & ~ASYNC_USR_MASK) | (sio.flags & ASYNC_USR_MASK);
1158 portp->baud_base = sio.baud_base;
1159 portp->close_delay = sio.close_delay;
1160 portp->closing_wait = sio.closing_wait;
1161 portp->custom_divisor = sio.custom_divisor;
1162 stl_setport(portp, portp->tty->termios);
1163 return(0);
1164 }
1165
1166
1167
1168 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1169 {
1170 stlport_t *portp;
1171 int rc;
1172
1173 #if DEBUG
1174 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n", (int) tty, (int) file, cmd, (int) arg);
1175 #endif
1176
1177 if (tty == (struct tty_struct *) NULL)
1178 return(-ENODEV);
1179 portp = tty->driver_data;
1180 if (portp == (stlport_t *) NULL)
1181 return(-ENODEV);
1182
1183 rc = 0;
1184
1185 switch (cmd) {
1186 case TCSBRK:
1187 if ((rc = tty_check_change(tty)) == 0) {
1188 tty_wait_until_sent(tty, 0);
1189 if (! arg)
1190 stl_sendbreak(portp, 250);
1191 }
1192 break;
1193 case TCSBRKP:
1194 if ((rc = tty_check_change(tty)) == 0) {
1195 tty_wait_until_sent(tty, 0);
1196 stl_sendbreak(portp, (arg ? (arg * 100) : 250));
1197 }
1198 break;
1199 case TIOCGSOFTCAR:
1200 if ((rc = verify_area(VERIFY_WRITE, (void *) arg, sizeof(long))) == 0)
1201 put_fs_long(((tty->termios->c_cflag & CLOCAL) ? 1 : 0), (unsigned long *) arg);
1202 break;
1203 case TIOCSSOFTCAR:
1204 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1205 arg = get_fs_long((unsigned long *) arg);
1206 tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0);
1207 }
1208 break;
1209 case TIOCMGET:
1210 if ((rc = verify_area(VERIFY_WRITE, (void *) arg, sizeof(unsigned int))) == 0) {
1211 stl_getsignals(portp);
1212 put_fs_long(portp->sigs, (unsigned long *) arg);
1213 }
1214 break;
1215 case TIOCMBIS:
1216 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1217 arg = get_fs_long((unsigned long *) arg);
1218 stl_setsignals(portp, ((arg & TIOCM_DTR) ? 1 : -1), ((arg & TIOCM_RTS) ? 1 : -1));
1219 }
1220 break;
1221 case TIOCMBIC:
1222 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1223 arg = get_fs_long((unsigned long *) arg);
1224 stl_setsignals(portp, ((arg & TIOCM_DTR) ? 0 : -1), ((arg & TIOCM_RTS) ? 0 : -1));
1225 }
1226 break;
1227 case TIOCMSET:
1228 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(long))) == 0) {
1229 arg = get_fs_long((unsigned long *) arg);
1230 stl_setsignals(portp, ((arg & TIOCM_DTR) ? 1 : 0), ((arg & TIOCM_RTS) ? 1 : 0));
1231 }
1232 break;
1233 case TIOCGSERIAL:
1234 if ((rc = verify_area(VERIFY_WRITE, (void *) arg, sizeof(struct serial_struct))) == 0)
1235 stl_getserial(portp, (struct serial_struct *) arg);
1236 break;
1237 case TIOCSSERIAL:
1238 if ((rc = verify_area(VERIFY_READ, (void *) arg, sizeof(struct serial_struct))) == 0)
1239 rc = stl_setserial(portp, (struct serial_struct *) arg);
1240 break;
1241 case TIOCSERCONFIG:
1242 case TIOCSERGWILD:
1243 case TIOCSERSWILD:
1244 case TIOCSERGETLSR:
1245 case TIOCSERGSTRUCT:
1246 case TIOCSERGETMULTI:
1247 case TIOCSERSETMULTI:
1248 default:
1249 rc = -ENOIOCTLCMD;
1250 break;
1251 }
1252
1253 return(rc);
1254 }
1255
1256
1257
1258 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1259 {
1260 stlport_t *portp;
1261 struct termios *tiosp;
1262
1263 #if DEBUG
1264 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1265 #endif
1266
1267 if (tty == (struct tty_struct *) NULL)
1268 return;
1269 portp = tty->driver_data;
1270 if (portp == (stlport_t *) NULL)
1271 return;
1272
1273 tiosp = tty->termios;
1274 if ((tiosp->c_cflag == old->c_cflag) && (tiosp->c_iflag == old->c_iflag))
1275 return;
1276
1277 stl_setport(portp, tiosp);
1278 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0), -1);
1279 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1280 tty->hw_stopped = 0;
1281 stl_start(tty);
1282 }
1283 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1284 wake_up_interruptible(&portp->open_wait);
1285 }
1286
1287
1288
1289
1290
1291
1292
1293
1294 static void stl_throttle(struct tty_struct *tty)
1295 {
1296 stlport_t *portp;
1297 unsigned long flags;
1298
1299 #if DEBUG
1300 printk("stl_throttle(tty=%x)\n", (int) tty);
1301 #endif
1302
1303 if (tty == (struct tty_struct *) NULL)
1304 return;
1305 portp = tty->driver_data;
1306 if (portp == (stlport_t *) NULL)
1307 return;
1308
1309 save_flags(flags);
1310 cli();
1311 BRDENABLE(portp->brdnr, portp->pagenr);
1312 stl_setreg(portp, CAR, (portp->portnr & 0x03));
1313 if (tty->termios->c_iflag & IXOFF) {
1314 stl_ccrwait(portp);
1315 stl_setreg(portp, CCR, CCR_SENDSCHR2);
1316 stl_ccrwait(portp);
1317 }
1318 if (tty->termios->c_cflag & CRTSCTS) {
1319 stl_setreg(portp, MCOR1, (stl_getreg(portp, MCOR1) & 0xf0));
1320 stl_setreg(portp, MSVR2, 0);
1321 }
1322 BRDDISABLE(portp->brdnr);
1323 restore_flags(flags);
1324 }
1325
1326
1327
1328
1329
1330
1331
1332 static void stl_unthrottle(struct tty_struct *tty)
1333 {
1334 stlport_t *portp;
1335 unsigned long flags;
1336
1337 #if DEBUG
1338 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1339 #endif
1340
1341 if (tty == (struct tty_struct *) NULL)
1342 return;
1343 portp = tty->driver_data;
1344 if (portp == (stlport_t *) NULL)
1345 return;
1346
1347 save_flags(flags);
1348 cli();
1349 BRDENABLE(portp->brdnr, portp->pagenr);
1350 stl_setreg(portp, CAR, (portp->portnr & 0x03));
1351 if (tty->termios->c_iflag & IXOFF) {
1352 stl_ccrwait(portp);
1353 stl_setreg(portp, CCR, CCR_SENDSCHR1);
1354 stl_ccrwait(portp);
1355 }
1356
1357
1358
1359
1360
1361
1362 if (tty->termios->c_cflag & CRTSCTS) {
1363 stl_setreg(portp, MCOR1, (stl_getreg(portp, MCOR1) | FIFO_RTSTHRESHOLD));
1364 stl_setreg(portp, MSVR2, MSVR2_RTS);
1365 }
1366 BRDDISABLE(portp->brdnr);
1367 restore_flags(flags);
1368 }
1369
1370
1371
1372
1373
1374
1375
1376
1377 static void stl_stop(struct tty_struct *tty)
1378 {
1379 stlport_t *portp;
1380
1381 #if DEBUG
1382 printk("stl_stop(tty=%x)\n", (int) tty);
1383 #endif
1384
1385 if (tty == (struct tty_struct *) NULL)
1386 return;
1387 portp = tty->driver_data;
1388 if (portp == (stlport_t *) NULL)
1389 return;
1390
1391 stl_startrxtx(portp, -1, 0);
1392 }
1393
1394
1395
1396
1397
1398
1399
1400 static void stl_start(struct tty_struct *tty)
1401 {
1402 stlport_t *portp;
1403
1404 #if DEBUG
1405 printk("stl_start(tty=%x)\n", (int) tty);
1406 #endif
1407
1408 if (tty == (struct tty_struct *) NULL)
1409 return;
1410 portp = tty->driver_data;
1411 if (portp == (stlport_t *) NULL)
1412 return;
1413
1414 stl_startrxtx(portp, -1, 1);
1415 }
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425 static void stl_hangup(struct tty_struct *tty)
1426 {
1427 stlport_t *portp;
1428
1429 #if DEBUG
1430 printk("stl_hangup(tty=%x)\n", (int) tty);
1431 #endif
1432
1433 if (tty == (struct tty_struct *) NULL)
1434 return;
1435 portp = tty->driver_data;
1436 if (portp == (stlport_t *) NULL)
1437 return;
1438
1439 portp->flags &= ~ASYNC_INITIALIZED;
1440 stl_disableintrs(portp);
1441 if (tty->termios->c_cflag & HUPCL)
1442 stl_setsignals(portp, 0, 0);
1443 stl_enablerxtx(portp, 0, 0);
1444 stl_flushbuffer(tty);
1445 portp->istate = 0;
1446 set_bit(TTY_IO_ERROR, &tty->flags);
1447 if (portp->tx.buf != (char *) NULL) {
1448 kfree_s(portp->tx.buf, STL_TXBUFSIZE);
1449 portp->tx.buf = (char *) NULL;
1450 portp->tx.head = (char *) NULL;
1451 portp->tx.tail = (char *) NULL;
1452 }
1453 tty->driver_data = (void *) NULL;
1454 portp->tty = (struct tty_struct *) NULL;
1455 portp->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CALLOUT_ACTIVE);
1456 portp->refcount = 0;
1457 wake_up_interruptible(&portp->open_wait);
1458 }
1459
1460
1461
1462 static void stl_flushbuffer(struct tty_struct *tty)
1463 {
1464 stlport_t *portp;
1465 unsigned long flags;
1466
1467 #if DEBUG
1468 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1469 #endif
1470
1471 if (tty == (struct tty_struct *) NULL)
1472 return;
1473 portp = tty->driver_data;
1474 if (portp == (stlport_t *) NULL)
1475 return;
1476
1477 save_flags(flags);
1478 cli();
1479 BRDENABLE(portp->brdnr, portp->pagenr);
1480 stl_setreg(portp, CAR, (portp->portnr & 0x03));
1481 stl_ccrwait(portp);
1482 stl_setreg(portp, CCR, CCR_TXFLUSHFIFO);
1483 stl_ccrwait(portp);
1484 portp->tx.tail = portp->tx.head;
1485 BRDDISABLE(portp->brdnr);
1486 restore_flags(flags);
1487
1488 wake_up_interruptible(&tty->write_wait);
1489 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1490 (tty->ldisc.write_wakeup)(tty);
1491 }
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501 static int stl_getreg(stlport_t *portp, int regnr)
1502 {
1503 outb((regnr + portp->uartaddr), portp->ioaddr);
1504 return(inb(portp->ioaddr + EREG_DATA));
1505 }
1506
1507 static void stl_setreg(stlport_t *portp, int regnr, int value)
1508 {
1509 outb((regnr + portp->uartaddr), portp->ioaddr);
1510 outb(value, portp->ioaddr + EREG_DATA);
1511 }
1512
1513 static int stl_updatereg(stlport_t *portp, int regnr, int value)
1514 {
1515 outb((regnr + portp->uartaddr), portp->ioaddr);
1516 if (inb(portp->ioaddr + EREG_DATA) != value) {
1517 outb(value, portp->ioaddr + EREG_DATA);
1518 return(1);
1519 }
1520 return(0);
1521 }
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537 static inline void stl_txisr(stlpanel_t *panelp, int ioaddr)
1538 {
1539 stlport_t *portp;
1540 int len, stlen;
1541 char *head, *tail;
1542 unsigned char ioack, srer;
1543
1544 #if DEBUG
1545 printk("stl_txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
1546 #endif
1547
1548 ioack = inb(ioaddr + EREG_TXACK);
1549 if (((ioack & panelp->ackmask) != 0) || ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
1550 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
1551 return;
1552 }
1553 portp = panelp->ports[(ioack >> 3)];
1554
1555
1556
1557
1558
1559
1560 if (portp->brklen != 0) {
1561 if (portp->brklen > 0) {
1562 outb((TDR + portp->uartaddr), ioaddr);
1563 outb(ETC_CMD, (ioaddr + EREG_DATA));
1564 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
1565 outb(ETC_CMD, (ioaddr + EREG_DATA));
1566 outb(ETC_DELAY, (ioaddr + EREG_DATA));
1567 outb(portp->brklen, (ioaddr + EREG_DATA));
1568 outb(ETC_CMD, (ioaddr + EREG_DATA));
1569 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
1570 portp->brklen = -1;
1571 goto stl_txalldone;
1572 } else {
1573 outb((COR2 + portp->uartaddr), ioaddr);
1574 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC), (ioaddr + EREG_DATA));
1575 portp->brklen = 0;
1576 }
1577 }
1578
1579 head = portp->tx.head;
1580 tail = portp->tx.tail;
1581 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1582 if ((len == 0) || ((len < STL_TXBUFLOW) && (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
1583 set_bit(ASYI_TXLOW, &portp->istate);
1584 queue_task_irq_off(&portp->tqueue, &tq_scheduler);
1585 }
1586
1587 if (len == 0) {
1588 outb((SRER + portp->uartaddr), ioaddr);
1589 srer = inb(ioaddr + EREG_DATA);
1590 if (srer & SRER_TXDATA) {
1591 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
1592 } else {
1593 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
1594 clear_bit(ASYI_TXBUSY, &portp->istate);
1595 }
1596 outb(srer, (ioaddr + EREG_DATA));
1597 } else {
1598 len = MIN(len, CD1400_TXFIFOSIZE);
1599 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
1600 outb((TDR + portp->uartaddr), ioaddr);
1601 outsb((ioaddr + EREG_DATA), tail, stlen);
1602 len -= stlen;
1603 tail += stlen;
1604 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
1605 tail = portp->tx.buf;
1606 if (len > 0) {
1607 outsb((ioaddr + EREG_DATA), tail, len);
1608 tail += len;
1609 }
1610 portp->tx.tail = tail;
1611 }
1612
1613 stl_txalldone:
1614 outb((EOSRR + portp->uartaddr), ioaddr);
1615 outb(0, (ioaddr + EREG_DATA));
1616 }
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630 static inline void stl_rxisr(stlpanel_t *panelp, int ioaddr)
1631 {
1632 stlport_t *portp;
1633 struct tty_struct *tty;
1634 unsigned int ioack, len, buflen;
1635 unsigned char status;
1636 char ch;
1637 static char unwanted[CD1400_RXFIFOSIZE];
1638
1639 #if DEBUG
1640 printk("stl_rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
1641 #endif
1642
1643 ioack = inb(ioaddr + EREG_RXACK);
1644 if ((ioack & panelp->ackmask) != 0) {
1645 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
1646 return;
1647 }
1648 portp = panelp->ports[(ioack >> 3)];
1649 tty = portp->tty;
1650
1651 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
1652 outb((RDCR + portp->uartaddr), ioaddr);
1653 len = inb(ioaddr + EREG_DATA);
1654 if ((tty == (struct tty_struct *) NULL) || (tty->flip.char_buf_ptr == (char *) NULL) ||
1655 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
1656 outb((RDSR + portp->uartaddr), ioaddr);
1657 insb((ioaddr + EREG_DATA), &unwanted[0], len);
1658 } else {
1659 len = MIN(len, buflen);
1660 if (len > 0) {
1661 outb((RDSR + portp->uartaddr), ioaddr);
1662 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
1663 memset(tty->flip.flag_buf_ptr, 0, len);
1664 tty->flip.flag_buf_ptr += len;
1665 tty->flip.char_buf_ptr += len;
1666 tty->flip.count += len;
1667 tty_schedule_flip(tty);
1668 }
1669 }
1670 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
1671 outb((RDSR + portp->uartaddr), ioaddr);
1672 status = inb(ioaddr + EREG_DATA);
1673 ch = inb(ioaddr + EREG_DATA);
1674 if ((tty != (struct tty_struct *) NULL) && ((portp->rxignoremsk & status) == 0)) {
1675 if (portp->rxmarkmsk & status) {
1676 if (status & ST_BREAK) {
1677 status = TTY_BREAK;
1678 #ifndef MODULE
1679 if (portp->flags & ASYNC_SAK)
1680 do_SAK(tty);
1681 #endif
1682 } else if (status & ST_PARITY) {
1683 status = TTY_PARITY;
1684 } else if (status & ST_FRAMING) {
1685 status = TTY_FRAME;
1686 } else if(status & ST_OVERRUN) {
1687 status = TTY_OVERRUN;
1688 } else {
1689 status = 0;
1690 }
1691 } else {
1692 status = 0;
1693 }
1694 if (tty->flip.char_buf_ptr != (char *) NULL) {
1695 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
1696 *tty->flip.flag_buf_ptr++ = status;
1697 *tty->flip.char_buf_ptr++ = ch;
1698 tty->flip.count++;
1699 }
1700 tty_schedule_flip(tty);
1701 }
1702 }
1703 } else {
1704 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
1705 return;
1706 }
1707
1708 outb((EOSRR + portp->uartaddr), ioaddr);
1709 outb(0, (ioaddr + EREG_DATA));
1710 }
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720 static inline void stl_mdmisr(stlpanel_t *panelp, int ioaddr)
1721 {
1722 stlport_t *portp;
1723 unsigned int ioack;
1724 unsigned char misr;
1725
1726 #if DEBUG
1727 printk("stl_mdmisr(panelp=%x)\n", (int) panelp);
1728 #endif
1729
1730 ioack = inb(ioaddr + EREG_MDACK);
1731 if (((ioack & panelp->ackmask) != 0) || ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
1732 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
1733 return;
1734 }
1735 portp = panelp->ports[(ioack >> 3)];
1736
1737 outb((MISR + portp->uartaddr), ioaddr);
1738 misr = inb(ioaddr + EREG_DATA);
1739 if (misr & MISR_DCD) {
1740 set_bit(ASYI_DCDCHANGE, &portp->istate);
1741 queue_task_irq_off(&portp->tqueue, &tq_scheduler);
1742 }
1743
1744 outb((EOSRR + portp->uartaddr), ioaddr);
1745 outb(0, (ioaddr + EREG_DATA));
1746 }
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758 static void stl_intr(int irq, struct pt_regs *regs)
1759 {
1760 stlbrd_t *brdp;
1761 stlpanel_t *panelp;
1762 unsigned char svrtype;
1763 int i, panelnr, iobase;
1764
1765 #if DEBUG
1766 printk("stl_intr(irq=%d,regs=%x)\n", irq, (int) regs);
1767 #endif
1768
1769 panelp = (stlpanel_t *) NULL;
1770 for (i = 0; (i < stl_nrbrds); ) {
1771 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL) {
1772 i++;
1773 continue;
1774 }
1775 if (brdp->state == 0) {
1776 i++;
1777 continue;
1778 }
1779
1780
1781
1782
1783
1784 if (brdp->brdtype == BRD_EASYIO) {
1785 if ((inb(brdp->iostatus) & EIO_INTRPEND) == 0) {
1786 i++;
1787 continue;
1788 }
1789 panelp = brdp->panels[0];
1790 iobase = panelp->iobase;
1791 outb(SVRR, iobase);
1792 svrtype = inb(iobase + EREG_DATA);
1793 if (brdp->nrports > 4) {
1794 outb((SVRR + 0x80), iobase);
1795 svrtype |= inb(iobase + EREG_DATA);
1796 }
1797 } else if (brdp->brdtype == BRD_ECH) {
1798 if ((inb(brdp->iostatus) & ECH_INTRPEND) == 0) {
1799 i++;
1800 continue;
1801 }
1802 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1803 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1804 panelp = brdp->panels[panelnr];
1805 iobase = panelp->iobase;
1806 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1807 break;
1808 if (panelp->nrports > 8) {
1809 iobase += 0x8;
1810 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1811 break;
1812 }
1813 }
1814 if (panelnr >= brdp->nrpanels) {
1815 i++;
1816 continue;
1817 }
1818 outb(SVRR, iobase);
1819 svrtype = inb(iobase + EREG_DATA);
1820 outb((SVRR + 0x80), iobase);
1821 svrtype |= inb(iobase + EREG_DATA);
1822 } else if (brdp->brdtype == BRD_ECHPCI) {
1823 iobase = brdp->ioaddr2;
1824 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1825 panelp = brdp->panels[panelnr];
1826 outb(panelp->pagenr, brdp->ioctrl);
1827 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1828 break;
1829 if (panelp->nrports > 8) {
1830 outb((panelp->pagenr + 1), brdp->ioctrl);
1831 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1832 break;
1833 }
1834 }
1835 if (panelnr >= brdp->nrpanels) {
1836 i++;
1837 continue;
1838 }
1839 outb(SVRR, iobase);
1840 svrtype = inb(iobase + EREG_DATA);
1841 outb((SVRR + 0x80), iobase);
1842 svrtype |= inb(iobase + EREG_DATA);
1843 } else if (brdp->brdtype == BRD_ECHMC) {
1844 if ((inb(brdp->iostatus) & ECH_INTRPEND) == 0) {
1845 i++;
1846 continue;
1847 }
1848 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1849 panelp = brdp->panels[panelnr];
1850 iobase = panelp->iobase;
1851 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1852 break;
1853 if (panelp->nrports > 8) {
1854 iobase += 0x8;
1855 if (inb(iobase + ECH_PNLSTATUS) & ECH_PNLINTRPEND)
1856 break;
1857 }
1858 }
1859 if (panelnr >= brdp->nrpanels) {
1860 i++;
1861 continue;
1862 }
1863 outb(SVRR, iobase);
1864 svrtype = inb(iobase + EREG_DATA);
1865 outb((SVRR + 0x80), iobase);
1866 svrtype |= inb(iobase + EREG_DATA);
1867 } else {
1868 printk("STALLION: unknown board type=%x\n", brdp->brdtype);
1869 i++;
1870 continue;
1871 }
1872
1873
1874
1875
1876
1877
1878 if (svrtype & SVRR_RX)
1879 stl_rxisr(panelp, iobase);
1880 if (svrtype & SVRR_TX)
1881 stl_txisr(panelp, iobase);
1882 if (svrtype & SVRR_MDM)
1883 stl_mdmisr(panelp, iobase);
1884
1885 if (brdp->brdtype == BRD_ECH)
1886 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1887 }
1888 }
1889
1890
1891
1892
1893
1894
1895
1896 static void stl_offintr(void *private)
1897 {
1898 stlport_t *portp;
1899 struct tty_struct *tty;
1900 unsigned int oldsigs;
1901
1902 portp = private;
1903 #if DEBUG
1904 printk("stl_offintr(portp=%x)\n", (int) portp);
1905 #endif
1906
1907 if (portp == (stlport_t *) NULL)
1908 return;
1909 tty = portp->tty;
1910 if (tty == (struct tty_struct *) NULL)
1911 return;
1912
1913 if (test_bit(ASYI_TXLOW, &portp->istate)) {
1914 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1915 (tty->ldisc.write_wakeup)(tty);
1916 wake_up_interruptible(&tty->write_wait);
1917 }
1918 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
1919 clear_bit(ASYI_DCDCHANGE, &portp->istate);
1920 oldsigs = portp->sigs;
1921 stl_getsignals(portp);
1922 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
1923 wake_up_interruptible(&portp->open_wait);
1924 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
1925 if (! ((portp->flags & ASYNC_CALLOUT_ACTIVE) &&
1926 (portp->flags & ASYNC_CALLOUT_NOHUP))) {
1927 tty_hangup(tty);
1928 }
1929 }
1930 }
1931 }
1932
1933
1934
1935
1936
1937
1938
1939
1940 static void stl_ccrwait(stlport_t *portp)
1941 {
1942 int i;
1943
1944 for (i = 0; (i < CCR_MAXWAIT); i++) {
1945 if (stl_getreg(portp, CCR) == 0) {
1946 return;
1947 }
1948 }
1949
1950 printk("STALLION: cd1400 device not responding, port=%d panel=%d brd=%d\n", portp->portnr, portp->panelnr, portp->brdnr);
1951 }
1952
1953
1954
1955
1956
1957
1958
1959
1960 static void stl_setport(stlport_t *portp, struct termios *tiosp)
1961 {
1962 stlbrd_t *brdp;
1963 unsigned long flags;
1964 unsigned int clkdiv, baudrate;
1965 unsigned char cor1, cor2, cor3;
1966 unsigned char cor4, cor5, ccr;
1967 unsigned char srer, sreron, sreroff;
1968 unsigned char mcor1, mcor2, rtpr;
1969 unsigned char clk, div;
1970
1971 cor1 = 0;
1972 cor2 = 0;
1973 cor3 = 0;
1974 cor4 = 0;
1975 cor5 = 0;
1976 ccr = 0;
1977 rtpr = 0;
1978 clk = 0;
1979 div = 0;
1980 mcor1 = 0;
1981 mcor2 = 0;
1982 sreron = 0;
1983 sreroff = 0;
1984
1985 brdp = stl_brds[portp->brdnr];
1986 if (brdp == (stlbrd_t *) NULL)
1987 return;
1988
1989
1990
1991
1992
1993
1994 portp->rxignoremsk = 0;
1995 if (tiosp->c_iflag & IGNPAR) {
1996 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
1997 cor1 |= COR1_PARIGNORE;
1998 }
1999 if (tiosp->c_iflag & IGNBRK) {
2000 portp->rxignoremsk |= ST_BREAK;
2001 cor4 |= COR4_IGNBRK;
2002 }
2003
2004 portp->rxmarkmsk = ST_OVERRUN;
2005 if (tiosp->c_iflag & (INPCK | PARMRK))
2006 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2007 if (tiosp->c_iflag & BRKINT)
2008 portp->rxmarkmsk |= ST_BREAK;
2009
2010
2011
2012
2013
2014 switch (tiosp->c_cflag & CSIZE) {
2015 case CS5:
2016 cor1 |= COR1_CHL5;
2017 break;
2018 case CS6:
2019 cor1 |= COR1_CHL6;
2020 break;
2021 case CS7:
2022 cor1 |= COR1_CHL7;
2023 break;
2024 default:
2025 cor1 |= COR1_CHL8;
2026 break;
2027 }
2028
2029 if (tiosp->c_cflag & CSTOPB)
2030 cor1 |= COR1_STOP2;
2031 else
2032 cor1 |= COR1_STOP1;
2033
2034 if (tiosp->c_cflag & PARENB) {
2035 if (tiosp->c_cflag & PARODD)
2036 cor1 |= (COR1_PARENB | COR1_PARODD);
2037 else
2038 cor1 |= (COR1_PARENB | COR1_PAREVEN);
2039 } else {
2040 cor1 |= COR1_PARNONE;
2041 }
2042
2043
2044
2045
2046
2047
2048
2049 cor3 |= FIFO_RXTHRESHOLD;
2050 rtpr = 2;
2051
2052
2053
2054
2055
2056
2057
2058 baudrate = tiosp->c_cflag & CBAUD;
2059 if (baudrate & CBAUDEX) {
2060 baudrate &= ~CBAUDEX;
2061 if ((baudrate < 1) || (baudrate > 2))
2062 tiosp->c_cflag &= ~CBAUDEX;
2063 else
2064 baudrate += 15;
2065 }
2066 baudrate = stl_baudrates[baudrate];
2067 if ((tiosp->c_cflag & CBAUD) == B38400) {
2068 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2069 baudrate = 57600;
2070 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2071 baudrate = 115200;
2072 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2073 baudrate = (portp->baud_base / portp->custom_divisor);
2074 }
2075 if (baudrate > STL_MAXBAUD)
2076 baudrate = STL_MAXBAUD;
2077
2078 if (baudrate > 0) {
2079 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
2080 clkdiv = ((CD1400_CLKHZ / stl_cd1400clkdivs[clk]) / baudrate);
2081 if (clkdiv < 0x100)
2082 break;
2083 }
2084 div = (unsigned char) clkdiv;
2085 }
2086
2087
2088
2089
2090 if ((tiosp->c_cflag & CLOCAL) == 0) {
2091 mcor1 |= MCOR1_DCD;
2092 mcor2 |= MCOR2_DCD;
2093 sreron |= SRER_MODEM;
2094 }
2095
2096
2097
2098
2099
2100
2101
2102 if (tiosp->c_iflag & IXON) {
2103 cor2 |= COR2_TXIBE;
2104 cor3 |= (COR3_FCT | COR3_SCD12);
2105 if (tiosp->c_iflag & IXANY)
2106 cor2 |= COR2_IXM;
2107 }
2108
2109 if (tiosp->c_cflag & CRTSCTS) {
2110 cor2 |= COR2_CTSAE;
2111 mcor1 |= FIFO_RTSTHRESHOLD;
2112 }
2113
2114
2115
2116
2117
2118
2119 #if DEBUG
2120 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr, portp->panelnr, portp->brdnr);
2121 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", cor1, cor2, cor3, cor4, cor5);
2122 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n", mcor1, mcor2, rtpr, sreron, sreroff);
2123 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
2124 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n", tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
2125 #endif
2126
2127 save_flags(flags);
2128 cli();
2129 BRDENABLE(portp->brdnr, portp->pagenr);
2130 stl_setreg(portp, CAR, (portp->portnr & 0x3));
2131 srer = stl_getreg(portp, SRER);
2132 stl_setreg(portp, SRER, 0);
2133 if (stl_updatereg(portp, COR1, cor1))
2134 ccr = 1;
2135 if (stl_updatereg(portp, COR2, cor2))
2136 ccr = 1;
2137 if (stl_updatereg(portp, COR3, cor3))
2138 ccr = 1;
2139 if (ccr) {
2140 stl_ccrwait(portp);
2141 stl_setreg(portp, CCR, CCR_CORCHANGE);
2142 }
2143 stl_setreg(portp, COR4, cor4);
2144 stl_setreg(portp, COR5, cor5);
2145 stl_setreg(portp, MCOR1, mcor1);
2146 stl_setreg(portp, MCOR2, mcor2);
2147 if (baudrate > 0) {
2148 stl_setreg(portp, TCOR, clk);
2149 stl_setreg(portp, TBPR, div);
2150 stl_setreg(portp, RCOR, clk);
2151 stl_setreg(portp, RBPR, div);
2152 }
2153 stl_setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
2154 stl_setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
2155 stl_setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
2156 stl_setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
2157 stl_setreg(portp, RTPR, rtpr);
2158 mcor1 = stl_getreg(portp, MSVR1);
2159 if (mcor1 & MSVR1_DCD)
2160 portp->sigs |= TIOCM_CD;
2161 else
2162 portp->sigs &= ~TIOCM_CD;
2163 stl_setreg(portp, SRER, ((srer & ~sreroff) | sreron));
2164 BRDDISABLE(portp->brdnr);
2165 restore_flags(flags);
2166 }
2167
2168
2169
2170
2171
2172
2173
2174 static void stl_setsignals(stlport_t *portp, int dtr, int rts)
2175 {
2176 unsigned char msvr1, msvr2;
2177 unsigned long flags;
2178
2179 #if DEBUG
2180 printk("stl_setsignals(portp=%x,dtr=%d,rts=%d)\n", (int) portp, dtr, rts);
2181 #endif
2182
2183 msvr1 = 0;
2184 msvr2 = 0;
2185 if (dtr > 0)
2186 msvr1 = MSVR1_DTR;
2187 if (rts > 0)
2188 msvr2 = MSVR2_RTS;
2189
2190 save_flags(flags);
2191 cli();
2192 BRDENABLE(portp->brdnr, portp->pagenr);
2193 stl_setreg(portp, CAR, (portp->portnr & 0x03));
2194 if (rts >= 0)
2195 stl_setreg(portp, MSVR2, msvr2);
2196 if (dtr >= 0)
2197 stl_setreg(portp, MSVR1, msvr1);
2198 BRDDISABLE(portp->brdnr);
2199 restore_flags(flags);
2200 }
2201
2202
2203
2204
2205
2206
2207
2208 static void stl_getsignals(stlport_t *portp)
2209 {
2210 unsigned char msvr1, msvr2;
2211 unsigned long flags;
2212
2213 #if DEBUG
2214 printk("stl_getsignals(portp=%x)\n", (int) portp);
2215 #endif
2216
2217 save_flags(flags);
2218 cli();
2219 BRDENABLE(portp->brdnr, portp->pagenr);
2220 stl_setreg(portp, CAR, (portp->portnr & 0x03));
2221 msvr1 = stl_getreg(portp, MSVR1);
2222 msvr2 = stl_getreg(portp, MSVR2);
2223 BRDDISABLE(portp->brdnr);
2224 portp->sigs = 0;
2225 portp->sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
2226 portp->sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
2227 portp->sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
2228 portp->sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
2229 portp->sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
2230 portp->sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
2231 restore_flags(flags);
2232 }
2233
2234
2235
2236
2237
2238
2239
2240 static void stl_enablerxtx(stlport_t *portp, int rx, int tx)
2241 {
2242 unsigned char ccr;
2243 unsigned long flags;
2244
2245 #if DEBUG
2246 printk("stl_enablerxtx(portp=%x,rx=%d,tx=%d)\n", (int) portp, rx, tx);
2247 #endif
2248 ccr = 0;
2249
2250 if (tx == 0)
2251 ccr |= CCR_TXDISABLE;
2252 else if (tx > 0)
2253 ccr |= CCR_TXENABLE;
2254 if (rx == 0)
2255 ccr |= CCR_RXDISABLE;
2256 else if (rx > 0)
2257 ccr |= CCR_RXENABLE;
2258
2259 save_flags(flags);
2260 cli();
2261 BRDENABLE(portp->brdnr, portp->pagenr);
2262 stl_setreg(portp, CAR, (portp->portnr & 0x03));
2263 stl_ccrwait(portp);
2264 stl_setreg(portp, CCR, ccr);
2265 stl_ccrwait(portp);
2266 BRDDISABLE(portp->brdnr);
2267 restore_flags(flags);
2268 }
2269
2270
2271
2272
2273
2274
2275
2276 static void stl_startrxtx(stlport_t *portp, int rx, int tx)
2277 {
2278 unsigned char sreron, sreroff;
2279 unsigned long flags;
2280
2281 #if DEBUG
2282 printk("stl_startrxtx(portp=%x,rx=%d,tx=%d)\n", (int) portp, rx, tx);
2283 #endif
2284
2285 sreron = 0;
2286 sreroff = 0;
2287 if (tx == 0)
2288 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
2289 else if (tx == 1)
2290 sreron |= SRER_TXDATA;
2291 else if (tx >= 2)
2292 sreron |= SRER_TXEMPTY;
2293 if (rx == 0)
2294 sreroff |= SRER_RXDATA;
2295 else if (rx > 0)
2296 sreron |= SRER_RXDATA;
2297
2298 save_flags(flags);
2299 cli();
2300 BRDENABLE(portp->brdnr, portp->pagenr);
2301 stl_setreg(portp, CAR, (portp->portnr & 0x03));
2302 stl_setreg(portp, SRER, ((stl_getreg(portp, SRER) & ~sreroff) | sreron));
2303 BRDDISABLE(portp->brdnr);
2304 if (tx > 0)
2305 set_bit(ASYI_TXBUSY, &portp->istate);
2306 restore_flags(flags);
2307 }
2308
2309
2310
2311
2312
2313
2314
2315 static void stl_disableintrs(stlport_t *portp)
2316 {
2317 unsigned long flags;
2318
2319 #if DEBUG
2320 printk("stl_disableintrs(portp=%x)\n", (int) portp);
2321 #endif
2322 save_flags(flags);
2323 cli();
2324 BRDENABLE(portp->brdnr, portp->pagenr);
2325 stl_setreg(portp, CAR, (portp->portnr & 0x03));
2326 stl_setreg(portp, SRER, 0);
2327 BRDDISABLE(portp->brdnr);
2328 restore_flags(flags);
2329 }
2330
2331
2332
2333 static void stl_sendbreak(stlport_t *portp, long len)
2334 {
2335 unsigned long flags;
2336
2337 #if DEBUG
2338 printk("stl_sendbreak(portp=%x,len=%d)\n", (int) portp, (int) len);
2339 #endif
2340
2341 save_flags(flags);
2342 cli();
2343 BRDENABLE(portp->brdnr, portp->pagenr);
2344 stl_setreg(portp, CAR, (portp->portnr & 0x03));
2345 stl_setreg(portp, COR2, (stl_getreg(portp, COR2) | COR2_ETC));
2346 stl_setreg(portp, SRER, ((stl_getreg(portp, SRER) & ~SRER_TXDATA) | SRER_TXEMPTY));
2347 BRDDISABLE(portp->brdnr);
2348 len = len / 5;
2349 portp->brklen = (len > 255) ? 255 : len;
2350 restore_flags(flags);
2351 }
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361 static int stl_mapirq(int irq)
2362 {
2363 int rc, i;
2364
2365 #if DEBUG
2366 printk("stl_mapirq(irq=%d)\n", irq);
2367 #endif
2368
2369 rc = 0;
2370 for (i = 0; (i < stl_numintrs); i++) {
2371 if (stl_gotintrs[i] == irq)
2372 break;
2373 }
2374 if (i >= stl_numintrs) {
2375 if (request_irq(irq, stl_intr, SA_INTERRUPT, stl_drvname) != 0) {
2376 printk("STALLION: failed to register interrupt routine for irq=%d\n", irq);
2377 rc = -ENODEV;
2378 } else {
2379 stl_gotintrs[stl_numintrs++] = irq;
2380 }
2381 }
2382 return(rc);
2383 }
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2394 {
2395 stlport_t *portp;
2396 unsigned int chipmask;
2397 unsigned int gfrcr;
2398 int nrchips, uartaddr, ioaddr;
2399 int i, j;
2400
2401 #if DEBUG
2402 printk("stl_initports(panelp=%x)\n", (int) panelp);
2403 #endif
2404
2405 BRDENABLE(panelp->brdnr, panelp->pagenr);
2406
2407
2408
2409
2410 chipmask = 0;
2411 nrchips = panelp->nrports / CD1400_PORTS;
2412 for (i = 0; (i < nrchips); i++) {
2413 if (brdp->brdtype == BRD_ECHPCI) {
2414 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
2415 ioaddr = panelp->iobase;
2416 } else {
2417 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2418 }
2419 uartaddr = (i & 0x01) ? 0x080 : 0;
2420 outb((GFRCR + uartaddr), ioaddr);
2421 outb(0, (ioaddr + EREG_DATA));
2422 outb((CCR + uartaddr), ioaddr);
2423 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2424 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2425 outb((GFRCR + uartaddr), ioaddr);
2426 for (j = 0; (j < CCR_MAXWAIT); j++) {
2427 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
2428 break;
2429 }
2430 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
2431 printk("STALLION: cd1400 not responding, brd=%d panel=%d chip=%d\n", panelp->brdnr, panelp->panelnr, i);
2432 continue;
2433 }
2434 chipmask |= (0x1 << i);
2435 outb((PPR + uartaddr), ioaddr);
2436 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
2437 }
2438
2439
2440
2441
2442
2443
2444 ioaddr = panelp->iobase;
2445 for (i = 0; (i < panelp->nrports); i++) {
2446 if (brdp->brdtype == BRD_ECHPCI) {
2447 outb((panelp->pagenr + (i >> 3)), brdp->ioctrl);
2448 ioaddr = panelp->iobase;
2449 } else {
2450 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 3));
2451 }
2452 if ((chipmask & (0x1 << (i / 4))) == 0)
2453 continue;
2454 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
2455 if (portp == (stlport_t *) NULL) {
2456 printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlport_t));
2457 break;
2458 }
2459 memset(portp, 0, sizeof(stlport_t));
2460 portp->portnr = i;
2461 portp->brdnr = panelp->brdnr;
2462 portp->panelnr = panelp->panelnr;
2463 portp->ioaddr = ioaddr;
2464 portp->uartaddr = (i & 0x04) << 5;
2465 portp->pagenr = panelp->pagenr + (i >> 3);
2466 portp->baud_base = STL_BAUDBASE;
2467 portp->close_delay = STL_CLOSEDELAY;
2468 portp->closing_wait = 30 * HZ;
2469 portp->normaltermios = stl_deftermios;
2470 portp->callouttermios = stl_deftermios;
2471 portp->tqueue.routine = stl_offintr;
2472 portp->tqueue.data = portp;
2473 stl_setreg(portp, CAR, (i & 0x03));
2474 stl_setreg(portp, LIVR, (i << 3));
2475 panelp->ports[i] = portp;
2476 }
2477
2478 BRDDISABLE(panelp->brdnr);
2479 return(0);
2480 }
2481
2482
2483
2484
2485
2486
2487
2488 static int stl_initeio(stlbrd_t *brdp)
2489 {
2490 stlpanel_t *panelp;
2491 unsigned int status;
2492 int rc;
2493
2494 #if DEBUG
2495 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2496 #endif
2497
2498 brdp->ioctrl = brdp->ioaddr1 + 1;
2499 brdp->iostatus = brdp->ioaddr1 + 2;
2500
2501 status = inb(brdp->iostatus);
2502 switch (status & EIO_IDBITMASK) {
2503 case EIO_8PORTRS:
2504 case EIO_8PORTM:
2505 case EIO_8PORTDI:
2506 brdp->nrports = 8;
2507 break;
2508 case EIO_4PORTRS:
2509 brdp->nrports = 4;
2510 break;
2511 default:
2512 return(-ENODEV);
2513 }
2514
2515 request_region(brdp->ioaddr1, 8, "serial(EIO)");
2516
2517
2518
2519
2520
2521
2522 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2523 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2524 printk("STALLION: invalid irq=%d for brd=%d\n", brdp->irq, brdp->brdnr);
2525 return(-EINVAL);
2526 }
2527 outb((stl_vecmap[brdp->irq] | ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)), brdp->ioctrl);
2528
2529 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2530 if (panelp == (stlpanel_t *) NULL) {
2531 printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlpanel_t));
2532 return(-ENOMEM);
2533 }
2534 memset(panelp, 0, sizeof(stlpanel_t));
2535
2536 panelp->brdnr = brdp->brdnr;
2537 panelp->panelnr = 0;
2538 panelp->nrports = brdp->nrports;
2539 panelp->iobase = brdp->ioaddr1;
2540 brdp->panels[0] = panelp;
2541 brdp->nrpanels = 1;
2542 brdp->state |= BRD_FOUND;
2543 rc = stl_mapirq(brdp->irq);
2544 return(rc);
2545 }
2546
2547
2548
2549
2550
2551
2552
2553
2554 static int stl_initech(stlbrd_t *brdp)
2555 {
2556 stlpanel_t *panelp;
2557 unsigned int status, nxtid;
2558 int panelnr, ioaddr, i;
2559
2560 #if DEBUG
2561 printk("stl_initech(brdp=%x)\n", (int) brdp);
2562 #endif
2563
2564
2565
2566
2567
2568
2569 if (brdp->brdtype == BRD_ECH) {
2570 brdp->ioctrl = brdp->ioaddr1 + 1;
2571 brdp->iostatus = brdp->ioaddr1 + 1;
2572 status = inb(brdp->iostatus);
2573 if ((status & ECH_IDBITMASK) != ECH_ID)
2574 return(-ENODEV);
2575
2576 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2577 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2578 printk("STALLION: invalid irq=%d for brd=%d\n", brdp->irq, brdp->brdnr);
2579 return(-EINVAL);
2580 }
2581 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2582 status |= (stl_vecmap[brdp->irq] << 1);
2583 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2584 brdp->ioctrlval = ECH_INTENABLE | ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2585 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2586 outb(status, brdp->ioaddr1);
2587
2588 request_region(brdp->ioaddr1, 2, "serial(EC8/32)");
2589 request_region(brdp->ioaddr2, 32, "serial(EC8/32-secondary)");
2590 } else if (brdp->brdtype == BRD_ECHMC) {
2591 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2592 brdp->iostatus = brdp->ioctrl;
2593 status = inb(brdp->iostatus);
2594 if ((status & ECH_IDBITMASK) != ECH_ID)
2595 return(-ENODEV);
2596
2597 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2598 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2599 printk("STALLION: invalid irq=%d for brd=%d\n", brdp->irq, brdp->brdnr);
2600 return(-EINVAL);
2601 }
2602 outb(ECHMC_BRDRESET, brdp->ioctrl);
2603 outb(ECHMC_INTENABLE, brdp->ioctrl);
2604
2605 request_region(brdp->ioaddr1, 64, "serial(EC8/32-MC)");
2606 } else if (brdp->brdtype == BRD_ECHPCI) {
2607 brdp->ioctrl = brdp->ioaddr1 + 2;
2608 request_region(brdp->ioaddr1, 4, "serial(EC8/32-PCI)");
2609 request_region(brdp->ioaddr2, 8, "serial(EC8/32-PCI-secondary)");
2610 }
2611
2612
2613
2614
2615
2616 ioaddr = brdp->ioaddr2;
2617 panelnr = 0;
2618 nxtid = 0;
2619
2620 for (i = 0; (i < STL_MAXPANELS); i++) {
2621 if (brdp->brdtype == BRD_ECHPCI) {
2622 outb(nxtid, brdp->ioctrl);
2623 ioaddr = brdp->ioaddr2;
2624 }
2625 status = inb(ioaddr + ECH_PNLSTATUS);
2626 if ((status & ECH_PNLIDMASK) != nxtid)
2627 break;
2628 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2629 if (panelp == (stlpanel_t *) NULL) {
2630 printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlpanel_t));
2631 break;
2632 }
2633 memset(panelp, 0, sizeof(stlpanel_t));
2634 panelp->brdnr = brdp->brdnr;
2635 panelp->panelnr = panelnr;
2636 panelp->iobase = ioaddr;
2637 panelp->pagenr = nxtid;
2638 if (status & ECH_PNL16PORT) {
2639 if ((brdp->nrports + 16) > 32)
2640 break;
2641 panelp->nrports = 16;
2642 panelp->ackmask = 0x80;
2643 brdp->nrports += 16;
2644 ioaddr += (EREG_BANKSIZE * 2);
2645 nxtid += 2;
2646 } else {
2647 panelp->nrports = 8;
2648 panelp->ackmask = 0xc0;
2649 brdp->nrports += 8;
2650 ioaddr += EREG_BANKSIZE;
2651 nxtid++;
2652 }
2653 brdp->panels[panelnr++] = panelp;
2654 brdp->nrpanels++;
2655 if (ioaddr >= (brdp->ioaddr2 + 0x20))
2656 break;
2657 }
2658
2659 if (brdp->brdtype == BRD_ECH)
2660 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2661
2662 brdp->state |= BRD_FOUND;
2663 i = stl_mapirq(brdp->irq);
2664 return(i);
2665 }
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676 static int stl_brdinit(stlbrd_t *brdp)
2677 {
2678 int i;
2679
2680 #if DEBUG
2681 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2682 #endif
2683
2684 switch (brdp->brdtype) {
2685 case BRD_EASYIO:
2686 stl_initeio(brdp);
2687 break;
2688 case BRD_ECH:
2689 case BRD_ECHMC:
2690 case BRD_ECHPCI:
2691 stl_initech(brdp);
2692 break;
2693 default:
2694 printk("STALLION: unit=%d is unknown board type=%d\n", brdp->brdnr, brdp->brdtype);
2695 return(ENODEV);
2696 }
2697
2698 stl_brds[brdp->brdnr] = brdp;
2699 if ((brdp->state & BRD_FOUND) == 0) {
2700 printk("STALLION: %s board not found, unit=%d io=%x irq=%d\n", stl_brdnames[brdp->brdtype], brdp->brdnr, brdp->ioaddr1, brdp->irq);
2701 return(ENODEV);
2702 }
2703
2704 for (i = 0; (i < STL_MAXPANELS); i++)
2705 if (brdp->panels[i] != (stlpanel_t *) NULL)
2706 stl_initports(brdp, brdp->panels[i]);
2707
2708 printk("STALLION: %s found, unit=%d io=%x irq=%d nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype], brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels, brdp->nrports);
2709 return(0);
2710 }
2711
2712
2713
2714
2715
2716
2717
2718
2719 #ifdef CONFIG_PCI
2720
2721 static int stl_findpcibrds()
2722 {
2723 stlbrd_t *brdp;
2724 unsigned char busnr, devnr, irq;
2725 unsigned short class;
2726 unsigned int ioaddr;
2727 int i, rc;
2728
2729 #if DEBUG
2730 printk("stl_findpcibrds()\n");
2731 #endif
2732
2733 if (pcibios_present()) {
2734 for (i = 0; (i < STL_MAXBRDS); i++) {
2735 if (pcibios_find_device(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, i, &busnr, &devnr))
2736 break;
2737
2738
2739
2740
2741
2742 if ((rc = pcibios_read_config_word(busnr, devnr, PCI_CLASS_DEVICE, &class))) {
2743 printk("STALLION: failed to read class type from PCI board, errno=%x\n", rc);
2744 continue;
2745 }
2746 if (class == PCI_CLASS_STORAGE_IDE)
2747 continue;
2748
2749 if (stl_nrbrds >= STL_MAXBRDS) {
2750 printk("STALLION: too many boards found, maximum supported %d\n", STL_MAXBRDS);
2751 break;
2752 }
2753
2754
2755
2756
2757
2758
2759 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
2760 if (brdp == (stlbrd_t *) NULL) {
2761 printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlbrd_t));
2762 return(-ENOMEM);
2763 }
2764 memset(brdp, 0, sizeof(stlbrd_t));
2765 brdp->brdnr = stl_nrbrds++;
2766 brdp->brdtype = BRD_ECHPCI;
2767
2768 if ((rc = pcibios_read_config_dword(busnr, devnr, PCI_BASE_ADDRESS_0, &ioaddr))) {
2769 printk("STALLION: failed to read BAR register from PCI board, errno=%x\n", rc);
2770 continue;
2771 }
2772 brdp->ioaddr2 = (ioaddr & PCI_BASE_ADDRESS_IO_MASK);
2773
2774 if ((rc = pcibios_read_config_dword(busnr, devnr, PCI_BASE_ADDRESS_1, &ioaddr))) {
2775 printk("STALLION: failed to read BAR register from PCI board, errno=%x\n", rc);
2776 continue;
2777 }
2778 brdp->ioaddr1 = (ioaddr & PCI_BASE_ADDRESS_IO_MASK);
2779 #if DEBUG
2780 printk("%s(%d): BAR0=%x BAR1=%x\n", __FILE__, __LINE__, brdp->ioaddr2, brdp->ioaddr1);
2781 #endif
2782
2783 if ((rc = pcibios_read_config_byte(busnr, devnr, PCI_INTERRUPT_LINE, &irq))) {
2784 printk("STALLION: failed to read BAR register from PCI board, errno=%x\n", rc);
2785 continue;
2786 }
2787 brdp->irq = irq;
2788
2789 #if 0
2790 ioaddr = 0x0c000001;
2791 if ((rc = pcibios_write_config_dword(busnr, devnr, 0x40, ioaddr))) {
2792 printk("STALLION: failed to write register on PCI board, errno=%x\n", rc);
2793 continue;
2794 }
2795 if ((rc = pcibios_write_config_dword(busnr, devnr, 0x48, ioaddr))) {
2796 printk("STALLION: failed to write register on PCI board, errno=%x\n", rc);
2797 continue;
2798 }
2799 #endif
2800
2801 stl_brdinit(brdp);
2802 }
2803 }
2804
2805 return(0);
2806 }
2807
2808 #endif
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818 static int stl_initbrds()
2819 {
2820 stlbrd_t *brdp;
2821 stlconf_t *confp;
2822 int i;
2823
2824 #if DEBUG
2825 printk("stl_initbrds()\n");
2826 #endif
2827
2828 if (stl_nrbrds > STL_MAXBRDS) {
2829 printk("STALLION: too many boards in configuration table, truncating to %d\n", STL_MAXBRDS);
2830 stl_nrbrds = STL_MAXBRDS;
2831 }
2832
2833
2834
2835
2836
2837 for (i = 0; (i < stl_nrbrds); i++) {
2838 confp = &stl_brdconf[i];
2839 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
2840 if (brdp == (stlbrd_t *) NULL) {
2841 printk("STALLION: failed to allocate memory (size=%d)\n", sizeof(stlbrd_t));
2842 return(-ENOMEM);
2843 }
2844 memset(brdp, 0, sizeof(stlbrd_t));
2845
2846 brdp->brdnr = i;
2847 brdp->brdtype = confp->brdtype;
2848 brdp->ioaddr1 = confp->ioaddr1;
2849 brdp->ioaddr2 = confp->ioaddr2;
2850 brdp->irq = confp->irq;
2851 brdp->irqtype = confp->irqtype;
2852 stl_brdinit(brdp);
2853 }
2854
2855 #ifdef CONFIG_PCI
2856
2857
2858
2859
2860 stl_findpcibrds();
2861 #endif
2862
2863 return(0);
2864 }
2865
2866
2867
2868 int stl_init(void)
2869 {
2870 printk("%s: version %s\n", stl_drvname, stl_drvversion);
2871
2872 stl_initbrds();
2873
2874
2875
2876
2877 stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
2878 if (stl_tmpwritebuf == (char *) NULL)
2879 printk("STALLION: failed to allocate memory (size=%d)\n", STL_TXBUFSIZE);
2880
2881
2882
2883
2884
2885 memset(&stl_serial, 0, sizeof(struct tty_driver));
2886 stl_serial.magic = TTY_DRIVER_MAGIC;
2887 stl_serial.name = stl_serialname;
2888 stl_serial.major = STL_SERIALMAJOR;
2889 stl_serial.minor_start = 0;
2890 stl_serial.num = STL_MAXBRDS * STL_MAXPORTS;
2891 stl_serial.type = TTY_DRIVER_TYPE_SERIAL;
2892 stl_serial.subtype = STL_DRVTYPSERIAL;
2893 stl_serial.init_termios = stl_deftermios;
2894 stl_serial.flags = TTY_DRIVER_REAL_RAW;
2895 stl_serial.refcount = &stl_refcount;
2896 stl_serial.table = stl_ttys;
2897 stl_serial.termios = stl_termios;
2898 stl_serial.termios_locked = stl_termioslocked;
2899
2900 stl_serial.open = stl_open;
2901 stl_serial.close = stl_close;
2902 stl_serial.write = stl_write;
2903 stl_serial.put_char = stl_putchar;
2904 stl_serial.flush_chars = stl_flushchars;
2905 stl_serial.write_room = stl_writeroom;
2906 stl_serial.chars_in_buffer = stl_charsinbuffer;
2907 stl_serial.ioctl = stl_ioctl;
2908 stl_serial.set_termios = stl_settermios;
2909 stl_serial.throttle = stl_throttle;
2910 stl_serial.unthrottle = stl_unthrottle;
2911 stl_serial.stop = stl_stop;
2912 stl_serial.start = stl_start;
2913 stl_serial.hangup = stl_hangup;
2914 stl_serial.flush_buffer = stl_flushbuffer;
2915
2916 stl_callout = stl_serial;
2917 stl_callout.name = stl_calloutname;
2918 stl_callout.major = STL_CALLOUTMAJOR;
2919 stl_callout.subtype = STL_DRVTYPCALLOUT;
2920
2921 if (tty_register_driver(&stl_serial))
2922 printk("STALLION: failed to register serial driver\n");
2923 if (tty_register_driver(&stl_callout))
2924 printk("STALLION: failed to register callout driver\n");
2925
2926 return 0;
2927 }
2928
2929