This source file includes following definitions.
- InReg
- OutReg
- wr
- or
- cl
- scc_enqueue_buffer
- scc_dequeue_buffer
- alloc_buffer_pool
- free_buffer_pool
- scc_get_buffer
- scc_isr_dispatch
- scc_isr
- scc_txint
- flush_FIFO
- scc_exint
- scc_rxint
- kick_rx_timer
- scc_spint
- set_brg
- set_speed
- init_brg
- init_channel
- scc_key_trx
- is_grouped
- dw_slot_timeout
- txdel_timeout
- tail_timeout
- busy_timeout
- maxk_idle_timeout
- scc_tx_timer
- scc_rx_timer
- scc_init_timer
- kiss_set_param
- kiss_interpret_frame
- kiss_store_byte
- kiss_decode
- kiss_encode
- z8530_init
- scc_paranoia_check
- scc_open
- scc_close
- scc_change_speed
- scc_ioctl
- scc_write
- scc_put_char
- scc_flush_chars
- scc_write_room
- scc_chars_in_buffer
- scc_flush_buffer
- scc_throttle
- scc_unthrottle
- scc_start
- scc_stop
- scc_set_termios
- scc_set_ldisc
- scc_init
- init_module
- cleanup_module
1 #define RCS_ID "$Id: scc.c,v 1.41 1995/12/17 22:36:40 jreuter Exp jreuter $"
2
3 #define BANNER "Z8530 SCC driver version 2.01.dl1bke (alpha) by DL1BKE\n"
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 #define DEBUG_BUFFERS
150
151 #undef SCC_DELAY
152 #undef SCC_LDELAY 5
153 #undef DONT_CHECK
154
155 #define MAXSCC 4
156 #define RXBUFFERS 8
157 #define TXBUFFERS 8
158 #define BUFSIZE 384
159 #define TPS 25
160
161 #define DEFAULT_CLOCK 4915200
162
163
164
165 #include <linux/module.h>
166 #include <linux/errno.h>
167 #include <linux/signal.h>
168 #include <linux/sched.h>
169 #include <linux/timer.h>
170 #include <linux/tqueue.h>
171 #include <linux/tty.h>
172 #include <linux/tty_driver.h>
173 #include <linux/tty_flip.h>
174 #include <linux/major.h>
175 #include <linux/termios.h>
176 #include <linux/serial.h>
177 #include <linux/interrupt.h>
178 #include <linux/ioport.h>
179 #include <linux/string.h>
180 #include <linux/fcntl.h>
181 #include <linux/ptrace.h>
182 #include <linux/malloc.h>
183 #include <linux/delay.h>
184 #include <linux/scc.h>
185
186 #include <asm/system.h>
187 #include <asm/io.h>
188 #include <asm/segment.h>
189 #include <asm/bitops.h>
190
191 #include <stdlib.h>
192 #include <stdio.h>
193 #include <ctype.h>
194 #include <time.h>
195 #include <linux/kernel.h>
196
197 #ifdef MODULE
198 int init_module(void);
199 void cleanup_module(void);
200 #endif
201
202 #ifndef Z8530_MAJOR
203 #define Z8530_MAJOR 34
204 #endif
205
206 int scc_init(void);
207
208 static struct mbuf * scc_enqueue_buffer(struct mbuf **queue, struct mbuf * buffer);
209 static struct mbuf * scc_dequeue_buffer(struct mbuf **queue);
210 static void alloc_buffer_pool(struct scc_channel *scc);
211 static void free_buffer_pool(struct scc_channel *scc);
212 static struct mbuf * scc_get_buffer(struct scc_channel *scc, char type);
213
214 int scc_open(struct tty_struct *tty, struct file *filp);
215 static void scc_close(struct tty_struct *tty, struct file *filp);
216 int scc_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
217 static void scc_put_char(struct tty_struct *tty, unsigned char ch);
218 static void scc_flush_chars(struct tty_struct *tty);
219 static int scc_write_room(struct tty_struct *tty);
220 static int scc_chars_in_buffer(struct tty_struct *tty);
221 static void scc_flush_buffer(struct tty_struct *tty);
222 static int scc_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
223 static void scc_set_termios(struct tty_struct *tty, struct termios *old_termios);
224 static void scc_set_ldisc(struct tty_struct *tty);
225 static void scc_throttle(struct tty_struct *tty);
226 static void scc_unthrottle(struct tty_struct *tty);
227 static void scc_start(struct tty_struct *tty);
228 static void scc_stop(struct tty_struct *tty);
229
230 static void z8530_init(void);
231
232 static void scc_change_speed(struct scc_channel *scc);
233 static void kiss_encode(struct scc_channel *scc);
234
235 static void init_channel(struct scc_channel *scc);
236 static void scc_key_trx (struct scc_channel *scc, char tx);
237 static void scc_txint(register struct scc_channel *scc);
238 static void scc_exint(register struct scc_channel *scc);
239 static void scc_rxint(register struct scc_channel *scc);
240 static void scc_spint(register struct scc_channel *scc);
241 static void scc_isr(int irq, struct pt_regs *regs);
242 static void scc_tx_timer(unsigned long);
243 static void scc_rx_timer(unsigned long);
244 static void scc_init_timer(struct scc_channel *scc);
245
246
247
248 static int baud_table[] = {
249 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
250 9600, 19200, 38400, 57600, 115200, 0 };
251
252
253 struct tty_driver scc_driver;
254 static int scc_refcount;
255 static struct tty_struct *scc_table[2*MAXSCC];
256 static struct termios scc_termios[2 * MAXSCC];
257 static struct termios scc_termios_locked[2 * MAXSCC];
258
259 struct irqflags { unsigned char used : 1; } Ivec[16];
260
261 struct scc_channel SCC_Info[2 * MAXSCC];
262 io_port SCC_ctrl[2 * MAXSCC];
263
264 unsigned char Random = 0;
265 unsigned char Driver_Initialized = 0;
266 int Nchips = 0;
267 io_port Vector_Latch = 0;
268
269 struct semaphore scc_sem = MUTEX;
270 unsigned char scc_wbuf[BUFSIZE];
271
272 static struct termios scc_std_termios;
273
274
275
276
277
278 static inline unsigned char
279 InReg(register io_port port, register unsigned char reg)
280 {
281 #ifdef SCC_LDELAY
282 register unsigned char r;
283 Outb(port, reg);
284 udelay(SCC_LDELAY);
285 r=Inb(port);
286 udelay(SCC_LDELAY);
287 return r;
288 #else
289 Outb(port, reg);
290 return Inb(port);
291 #endif
292 }
293
294 static inline void
295 OutReg(register io_port port, register unsigned char reg, register unsigned char val)
296 {
297 #ifdef SCC_LDELAY
298 Outb(port, reg); udelay(SCC_LDELAY);
299 Outb(port, val); udelay(SCC_LDELAY);
300 #else
301 Outb(port, reg);
302 Outb(port, val);
303 #endif
304 }
305
306 static inline void
307 wr(register struct scc_channel *scc, register unsigned char reg, register unsigned char val)
308 {
309 OutReg(scc->ctrl, reg, (scc->wreg[reg] = val));
310 }
311
312 static inline void
313 or(register struct scc_channel *scc, register unsigned char reg, register unsigned char val)
314 {
315 OutReg(scc->ctrl, reg, (scc->wreg[reg] |= val));
316 }
317
318 static inline void
319 cl(register struct scc_channel *scc, register unsigned char reg, register unsigned char val)
320 {
321 OutReg(scc->ctrl, reg, (scc->wreg[reg] &= ~val));
322 }
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349 static struct mbuf *
350 scc_enqueue_buffer(struct mbuf **queue, struct mbuf * buffer)
351 {
352 unsigned long flags;
353 struct mbuf * anchor;
354
355 save_flags(flags); cli();
356
357 #ifdef DEBUG_BUFFERS
358 if (queue == NULLBUFP)
359
360 {
361 printk("z8530drv: Pointer to queue anchor is NULL pointer [enq]\n");
362 restore_flags(flags);
363 return NULLBUF;
364 }
365
366 if (buffer == NULLBUF)
367 {
368 printk("z8530drv: can't enqueue a NULL pointer\n");
369 restore_flags(flags);
370 return NULLBUF;
371 }
372 #endif
373
374 anchor = *queue;
375
376 if (anchor == NULLBUF)
377 {
378 *queue = buffer;
379 buffer->next = buffer->prev = NULLBUF;
380 } else
381 if (anchor->prev == NULLBUF)
382 {
383 #ifdef DEBUG_BUFFERS
384 if (anchor->prev != NULLBUF)
385 printk("weird --- anchor->prev is NULL but not anchor->next [enq]\n");
386 #endif
387 anchor->next = anchor->prev = buffer;
388 buffer->next = buffer->prev = anchor;
389 } else
390 #ifdef DEBUG_BUFFERS
391 if (anchor->next == NULLBUF)
392 {
393 printk("z8530drv: weird --- anchor->next is NULL but not anchor->prev [enq]\n");
394 anchor->next = anchor->prev = buffer;
395 buffer->next = buffer->prev = anchor;
396 } else
397 #endif
398 {
399 buffer->prev = anchor->prev;
400 buffer->next = anchor;
401 anchor->prev->next = buffer;
402 anchor->prev = buffer;
403 }
404
405 restore_flags(flags);
406 return *queue;
407 }
408
409
410
411
412
413 static struct mbuf *
414 scc_dequeue_buffer(struct mbuf **queue)
415 {
416 unsigned long flags;
417 struct mbuf *buffer;
418
419 save_flags(flags); cli();
420
421 #ifdef DEBUG_BUFFERS
422 if (queue == NULLBUFP)
423
424 {
425 printk("z8530drv: Pointer to queue anchor is NULL pointer [deq]\n");
426 restore_flags(flags);
427 return NULLBUF;
428 }
429 #endif
430
431 buffer = *queue;
432
433 if (buffer != NULLBUF)
434 {
435 if (buffer->prev != NULLBUF)
436 {
437 #ifdef DEBUG_BUFFERS
438 if (buffer->next == NULLBUF)
439 {
440 printk("z8530drv: weird --- buffer->next is NULL but not buffer->prev [deq]\n");
441 } else
442 #endif
443 if (buffer->prev->next == buffer->prev->prev)
444 {
445 buffer->next->prev = NULLBUF;
446 buffer->next->next = NULLBUF;
447 } else {
448 buffer->next->prev = buffer->prev;
449 buffer->prev->next = buffer->next;
450 }
451 }
452 #ifdef DEBUG_BUFFERS
453 else if (buffer->next != NULLBUF)
454 printk("z8530drv: weird --- buffer->prev is NULL but not buffer->next [deq]\n");
455 #endif
456 *queue = buffer->next;
457
458 buffer->next = NULLBUF;
459 buffer->prev = NULLBUF;
460 buffer->rw_ptr = buffer->data;
461 }
462
463 restore_flags(flags);
464 return buffer;
465 }
466
467
468
469
470
471
472 static void
473 alloc_buffer_pool(struct scc_channel *scc)
474 {
475 int k;
476 struct mbuf * bptr;
477 int buflen;
478
479 buflen = sizeof(struct mbuf) + scc->stat.bufsize;
480
481 if (scc->stat.bufsize < 336) scc->stat.bufsize = 336;
482 if (buflen > 4096)
483 {
484 scc->stat.bufsize = 4096-sizeof(struct mbuf);
485 buflen = 4096;
486 }
487
488 if (scc->stat.rxbuffers < 4) scc->stat.rxbuffers = 4;
489 if (scc->stat.txbuffers < 4) scc->stat.txbuffers = 4;
490
491
492
493
494
495 for (k = 0; k < scc->stat.rxbuffers ; k++)
496 {
497
498
499 bptr = (struct mbuf *) kmalloc(buflen, GFP_ATOMIC);
500
501
502
503 if (bptr == NULLBUF)
504 {
505 printk("z8530drv: %s: can't allocate memory for rx buffer pool", kdevname(scc->tty->device));
506 break;
507 }
508
509
510
511 memset(bptr, 0, buflen);
512
513
514
515 bptr->rw_ptr = bptr->data;
516
517
518
519 scc_enqueue_buffer(&scc->rx_buffer_pool, bptr);
520 }
521
522
523
524 for (k = 0; k < scc->stat.txbuffers ; k++)
525 {
526 bptr = (struct mbuf *) kmalloc(buflen, GFP_ATOMIC);
527
528 if (bptr == NULLBUF)
529 {
530 printk("z8530drv: %s: can't allocate memory for tx buffer pool", kdevname(scc->tty->device));
531 break;
532 }
533
534 memset(bptr, 0, buflen);
535
536 bptr->rw_ptr = bptr->data;
537
538 scc_enqueue_buffer(&scc->tx_buffer_pool, bptr);
539 }
540 }
541
542
543
544
545 static void
546 free_buffer_pool(struct scc_channel *scc)
547 {
548 struct mbuf * bptr;
549 unsigned long flags;
550 int cnt;
551
552
553
554 save_flags(flags); cli();
555
556
557
558 bptr = scc->rx_bp;
559 if (bptr != NULLBUF)
560 {
561 scc->rx_bp = NULLBUF;
562 scc_enqueue_buffer(&scc->rx_buffer_pool, bptr);
563 }
564
565 bptr = scc->tx_bp;
566 if (bptr != NULLBUF)
567 {
568 scc->tx_bp = NULLBUF;
569 scc_enqueue_buffer(&scc->tx_buffer_pool, bptr);
570 }
571
572 bptr = scc->kiss_decode_bp;
573 if (bptr != NULLBUF)
574 {
575 scc->kiss_decode_bp = NULLBUF;
576 scc_enqueue_buffer(&scc->tx_buffer_pool, bptr);
577 }
578
579 bptr = scc->kiss_encode_bp;
580 if (bptr != NULLBUF)
581 {
582 scc->kiss_encode_bp = NULLBUF;
583 scc_enqueue_buffer(&scc->rx_buffer_pool, bptr);
584 }
585
586 restore_flags(flags);
587
588
589 while (scc->rx_queue != NULLBUF)
590 {
591 bptr = scc_dequeue_buffer(&scc->rx_queue);
592 scc_enqueue_buffer(&scc->rx_buffer_pool, bptr);
593 }
594
595 while (scc->tx_queue != NULLBUF)
596 {
597 bptr = scc_dequeue_buffer(&scc->tx_queue);
598 scc_enqueue_buffer(&scc->tx_buffer_pool, bptr);
599 }
600
601
602
603
604
605 cnt = 0;
606
607
608
609
610
611 while (scc->rx_buffer_pool != NULLBUF)
612 {
613 bptr = scc_dequeue_buffer(&scc->rx_buffer_pool);
614
615 if (bptr != NULLBUF)
616 {
617 cnt++;
618 kfree(bptr);
619 }
620 }
621
622 if (cnt < scc->stat.rxbuffers)
623 printk("z8530drv: oops, deallocated only %d of %d rx buffers\n", cnt, scc->stat.rxbuffers);
624 if (cnt > scc->stat.rxbuffers)
625 printk("z8530drv: oops, deallocated %d instead of %d rx buffers. Very strange.\n", cnt, scc->stat.rxbuffers);
626
627 cnt = 0;
628
629 while (scc->tx_buffer_pool != NULLBUF)
630 {
631 bptr = scc_dequeue_buffer(&scc->tx_buffer_pool);
632
633 if (bptr != NULLBUF)
634 {
635 cnt++;
636 kfree(bptr);
637 }
638 }
639
640 if (cnt < scc->stat.txbuffers)
641 printk("z8530drv: oops, deallocated only %d of %d tx buffers\n", cnt, scc->stat.txbuffers);
642 if (cnt > scc->stat.txbuffers)
643 printk("z8530drv: oops, deallocated %d instead of %d tx buffers. Very strange.\n", cnt, scc->stat.txbuffers);
644 }
645
646
647
648
649
650
651
652
653
654
655
656 static struct mbuf *
657 scc_get_buffer(struct scc_channel *scc, char type)
658 {
659 struct mbuf * bptr;
660
661 if (type == BT_TRANSMIT)
662 {
663 bptr = scc_dequeue_buffer(&scc->tx_buffer_pool);
664
665
666
667 if (bptr == NULLBUF)
668 {
669 printk("z8530drv: scc_get_buffer(%s): tx buffer pool empty\n", kdevname(scc->tty->device));
670
671
672
673 bptr = scc_dequeue_buffer(&scc->tx_queue);
674
675
676
677 if (bptr == NULLBUF)
678 printk("z8530drv: scc_get_buffer(): panic - even no buffer found in tx queue\n");
679 }
680 } else {
681 bptr = scc_dequeue_buffer(&scc->rx_buffer_pool);
682
683 if (bptr == NULLBUF)
684 {
685 printk("z8530drv: scc_get_buffer(%s): rx buffer pool empty\n", kdevname(scc->tty->device));
686
687 bptr = scc_dequeue_buffer(&scc->rx_queue);
688
689 if (bptr == NULLBUF)
690 printk("z8530drv: scc_get_buffer(): panic - even no buffer found in rx queue\n");
691 }
692 }
693
694 if (bptr != NULLBUF)
695 {
696 bptr->rw_ptr = bptr->data;
697 bptr->cnt = 0;
698 }
699
700 return bptr;
701 }
702
703
704
705
706
707
708
709
710
711
712 static inline void
713 scc_isr_dispatch(register struct scc_channel *scc, register int vector)
714 {
715 switch (vector & VECTOR_MASK)
716 {
717 case TXINT: scc_txint(scc); break;
718 case EXINT: scc_exint(scc); break;
719 case RXINT: scc_rxint(scc); break;
720 case SPINT: scc_spint(scc); break;
721 default : printk("scc_isr(): unknown interrupt status (addr %4.4x, state %2.2x)\n",scc->ctrl,vector);
722 }
723 }
724
725
726
727
728
729
730
731
732
733
734 static void
735 scc_isr(int irq, struct pt_regs *regs)
736 {
737 register unsigned char vector;
738 register struct scc_channel *scc;
739 register io_port q;
740 register io_port *p;
741 register int k;
742
743
744 cli();
745
746 if (Vector_Latch)
747 {
748 while(1)
749 {
750 Outb(Vector_Latch, 0);
751
752
753 if((vector=Inb(Vector_Latch)) >= 16 * Nchips) break;
754
755
756
757
758
759
760 if (vector & 0x01) break;
761
762 scc=&SCC_Info[(((vector>>1)&0x7c)^0x04) >> 2];
763
764 if (!scc->tty) break;
765
766 scc_isr_dispatch(scc, vector);
767
768 Outb(scc->ctrl,0x38);
769 }
770
771 sti();
772 return;
773 }
774
775
776
777
778
779
780 k = 0;
781 p = SCC_ctrl;
782
783 while (k++ < Nchips)
784 {
785 if (!(q=*p++)) break;
786
787 Outb(q,3);
788
789 if (Inb(q))
790 {
791 if (!(q=*p++)) break;
792
793 Outb(q,2);
794 vector=Inb(q);
795
796
797
798
799
800
801 if (vector & 1) break;
802
803 scc = &SCC_Info[(((vector >> 1) & 0x7c) ^ 0x04) >> 2];
804
805 if (!scc->tty) break;
806
807
808
809 scc_isr_dispatch(scc, vector);
810
811 k = 0;
812 p = SCC_ctrl;
813
814 } else p++;
815 }
816
817 sti();
818 }
819
820
821
822
823
824
825
826
827 static void
828 scc_txint(register struct scc_channel *scc)
829 {
830 register struct mbuf *bp;
831
832 scc->stat.txints++;
833
834 bp = scc->tx_bp;
835
836 if (bp == NULLBUF)
837 {
838 do
839 {
840 if (bp != NULLBUF)
841 scc_enqueue_buffer(&scc->tx_buffer_pool, bp);
842
843 bp = scc_dequeue_buffer(&scc->tx_queue);
844
845 if (bp == NULLBUF)
846 {
847 scc->stat.tx_state = TXS_BUSY;
848 scc->t_tail = scc->kiss.tailtime;
849
850 Outb(scc->ctrl, RES_Tx_P);
851 return;
852 }
853
854 if ( scc->kiss.not_slip && (bp->cnt > 0) )
855 {
856 bp->rw_ptr++;
857 bp->cnt--;
858 }
859
860 } while (bp->cnt < 1);
861
862
863 Outb(scc->ctrl, RES_Tx_CRC);
864 or(scc,R10,ABUNDER);
865 Outb(scc->data,*bp->rw_ptr);
866 if (!scc->enhanced)
867 Outb(scc->ctrl, RES_EOM_L);
868
869 scc->tx_bp = bp;
870 scc->stat.tx_state = TXS_ACTIVE;
871 } else
872 if (bp->cnt <= 0)
873 {
874 if (--scc->stat.tx_queued < 0) scc->stat.tx_queued = 0;
875
876 Outb(scc->ctrl, RES_Tx_P);
877 cl(scc, R10, ABUNDER);
878 scc_enqueue_buffer(&scc->tx_buffer_pool, bp);
879 scc->tx_bp = NULLBUF;
880 scc->stat.tx_state = TXS_NEWFRAME;
881 return;
882 } else {
883 Outb(scc->data,*bp->rw_ptr);
884 }
885
886 bp->rw_ptr++;
887 bp->cnt--;
888 }
889
890 static inline void
891 flush_FIFO(register struct scc_channel *scc)
892 {
893 register int k;
894
895 for (k=0; k<3; k++)
896 Inb(scc->data);
897
898 if(scc->rx_bp != NULLBUF)
899 {
900 scc->stat.rxerrs++;
901 scc_enqueue_buffer(&scc->rx_buffer_pool, scc->rx_bp);
902
903 scc->rx_bp = NULLBUF;
904 }
905 }
906
907
908
909 static void
910 scc_exint(register struct scc_channel *scc)
911 {
912 register unsigned char status,changes,chg_and_stat;
913
914 scc->stat.exints++;
915
916 status = InReg(scc->ctrl,R0);
917 changes = status ^ scc->status;
918 chg_and_stat = changes & status;
919
920
921
922 if (chg_and_stat & BRK_ABRT)
923 flush_FIFO(scc);
924
925
926
927
928
929 if(changes & DCD)
930 {
931 if(status & DCD)
932 {
933 if (scc->modem.clocksrc != CLK_EXTERNAL)
934 OutReg(scc->ctrl,R14,SEARCH|scc->wreg[R14]);
935
936 or(scc,R3,ENT_HM|RxENABLE);
937 } else {
938 cl(scc,R3,ENT_HM|RxENABLE);
939 flush_FIFO(scc);
940 }
941 }
942
943 #ifdef notdef
944
945
946 if (chg_and_stat & CTS)
947 {
948 if (!Running(t_txdel) && scc->kiss.txdelay == 0)
949 scc->t_txdel = 0;
950
951 }
952 #endif
953
954 if ( (status & TxEOM) && (scc->stat.tx_state == TXS_ACTIVE) )
955 {
956 scc->stat.tx_under++;
957 Outb(scc->ctrl, RES_Tx_P);
958 Outb(scc->ctrl, RES_EXT_INT);
959 scc->t_maxk = 1;
960
961 if (scc->tx_bp != NULLBUF)
962 {
963 scc_enqueue_buffer(&scc->tx_buffer_pool, scc->tx_bp);
964 scc->tx_bp = NULLBUF;
965 }
966
967 if (--scc->stat.tx_queued < 0) scc->stat.tx_queued = 0;
968 or(scc,R10,ABUNDER);
969 }
970
971 if (status & ZCOUNT)
972 {
973 scc->stat.tx_under = 9999;
974 Outb(scc->ctrl, RES_Tx_P);
975 scc->t_maxk = 1;
976
977 if (scc->tx_bp != NULLBUF)
978 {
979 scc_enqueue_buffer(&scc->tx_buffer_pool, scc->tx_bp);
980 scc->tx_bp = NULLBUF;
981 }
982
983 if (--scc->stat.tx_queued < 0) scc->stat.tx_queued = 0;
984 scc->kiss.tx_inhibit = 1;
985 }
986
987
988 scc->status = status;
989 Outb(scc->ctrl,RES_EXT_INT);
990 }
991
992
993
994 static void
995 scc_rxint(register struct scc_channel *scc)
996 {
997 register struct mbuf *bp;
998
999 scc->stat.rxints++;
1000
1001 if( Running(t_maxk) && !(scc->kiss.fulldup))
1002 {
1003 Inb(scc->data);
1004 or(scc,R3,ENT_HM);
1005 return;
1006 }
1007
1008 bp = scc->rx_bp;
1009
1010 if (bp == NULLBUF)
1011 {
1012 bp = scc_get_buffer(scc, BT_RECEIVE);
1013 if (bp == NULLBUF)
1014 {
1015 printk("scc_rxint(): panic --- cannot get a buffer\n");
1016 Inb(scc->data);
1017 or(scc, R3, ENT_HM);
1018 scc->stat.nospace++;
1019 return;
1020 }
1021
1022 scc->rx_bp = bp;
1023 }
1024
1025 if (bp->cnt > scc->stat.bufsize)
1026 {
1027 #ifdef notdef
1028 printk("scc_rxint(): oops, received huge frame...\n");
1029 #endif
1030 scc_enqueue_buffer(&scc->rx_buffer_pool, bp);
1031 scc->rx_bp = NULLBUF;
1032 Inb(scc->data);
1033 or(scc, R3, ENT_HM);
1034 return;
1035 }
1036
1037
1038 *bp->rw_ptr = Inb(scc->data);
1039 bp->rw_ptr++;
1040 bp->cnt++;
1041 }
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052 static inline void
1053 kick_rx_timer(register struct scc_channel *scc)
1054 {
1055 if (scc->rx_t.next)
1056 del_timer(&(scc->rx_t));
1057
1058 scc->rx_t.expires = jiffies + 1;
1059 scc->rx_t.function = scc_rx_timer;
1060 scc->rx_t.data = (unsigned long) scc;
1061 add_timer(&scc->rx_t);
1062 }
1063
1064
1065 static void
1066 scc_spint(register struct scc_channel *scc)
1067 {
1068 register unsigned char status;
1069 register struct mbuf *bp;
1070
1071 scc->stat.spints++;
1072
1073 status = InReg(scc->ctrl,R1);
1074
1075 Inb(scc->data);
1076 bp = scc->rx_bp;
1077
1078 if(status & Rx_OVR)
1079 {
1080 scc->stat.rx_over++;
1081 or(scc,R3,ENT_HM);
1082
1083 if (bp) scc_enqueue_buffer(&scc->rx_buffer_pool, bp);
1084 scc->rx_bp = NULLBUF;
1085 }
1086
1087 if(status & END_FR && bp != NULLBUF)
1088 {
1089
1090
1091 if (!(status & CRC_ERR) && (status & 0xe) == RES8 && bp->cnt)
1092 {
1093
1094 bp->cnt--;
1095
1096 scc_enqueue_buffer(&scc->rx_queue, bp);
1097 scc->rx_bp = NULLBUF;
1098 scc->stat.rxframes++;
1099 scc->stat.rx_queued++;
1100 kick_rx_timer(scc);
1101 } else {
1102 scc_enqueue_buffer(&scc->rx_buffer_pool, bp);
1103 scc->rx_bp = NULLBUF;
1104 scc->stat.rxerrs++;
1105 }
1106 }
1107
1108 Outb(scc->ctrl,ERR_RES);
1109 }
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119 static inline void set_brg(register struct scc_channel *scc, unsigned int tc)
1120 {
1121 unsigned long flags;
1122
1123 save_flags(flags); cli();
1124
1125 cl(scc,R14,BRENABL);
1126 wr(scc,R12,tc & 255);
1127 wr(scc,R13,tc >> 8);
1128 or(scc,R14,BRENABL);
1129
1130 restore_flags(flags);
1131 }
1132
1133 static inline void set_speed(register struct scc_channel *scc)
1134 {
1135 if (scc->modem.speed > 0)
1136 set_brg(scc, (unsigned) (scc->clock / (scc->modem.speed * 64)) - 2);
1137 }
1138
1139
1140
1141
1142 static inline void init_brg(register struct scc_channel *scc)
1143 {
1144 wr(scc, R14, BRSRC);
1145 OutReg(scc->ctrl, R14, SSBR|scc->wreg[R14]);
1146 OutReg(scc->ctrl, R14, SNRZI|scc->wreg[R14]);
1147 }
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194 static void
1195 init_channel(register struct scc_channel *scc)
1196 {
1197 unsigned long flags;
1198
1199 if (scc->rx_t.next) del_timer(&(scc->rx_t));
1200 if (scc->tx_t.next) del_timer(&(scc->tx_t));
1201
1202 save_flags(flags); cli();
1203
1204 wr(scc,R4,X1CLK|SDLC);
1205 wr(scc,R1,0);
1206 wr(scc,R3,Rx8|RxCRC_ENAB);
1207 wr(scc,R5,Tx8|DTR|TxCRC_ENAB);
1208 wr(scc,R6,0);
1209 wr(scc,R7,FLAG);
1210 wr(scc,R9,VIS);
1211 wr(scc,R10,(scc->modem.nrz? NRZ : NRZI)|CRCPS|ABUNDER);
1212 wr(scc,R14, 0);
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241 switch(scc->modem.clocksrc)
1242 {
1243 case CLK_DPLL:
1244 wr(scc, R11, RCDPLL|TCDPLL|TRxCOI|TRxCDP);
1245 init_brg(scc);
1246 break;
1247
1248 case CLK_DIVIDER:
1249 wr(scc, R11, ((scc->brand & BAYCOM)? TRxCDP : TRxCBR) | RCDPLL|TCRTxCP|TRxCOI);
1250 init_brg(scc);
1251 break;
1252
1253 case CLK_EXTERNAL:
1254 wr(scc, R11, (scc->brand & BAYCOM)? RCTRxCP|TCRTxCP : RCRTxCP|TCTRxCP);
1255 OutReg(scc->ctrl, R14, DISDPLL);
1256 break;
1257
1258 }
1259
1260 set_speed(scc);
1261
1262 if(scc->enhanced)
1263 {
1264 or(scc,R15,SHDLCE|FIFOE);
1265 wr(scc,R7,AUTOEOM);
1266 }
1267
1268 if((InReg(scc->ctrl,R0)) & DCD)
1269 {
1270 if (scc->modem.clocksrc != CLK_EXTERNAL)
1271 or(scc,R14, SEARCH);
1272
1273 or(scc,R3,ENT_HM|RxENABLE);
1274 }
1275
1276
1277 wr(scc,R15,((scc->brand & BAYCOM) ? 0 : CTSIE)|BRKIE|DCDIE|TxUIE);
1278
1279 Outb(scc->ctrl,RES_EXT_INT);
1280 Outb(scc->ctrl,RES_EXT_INT);
1281
1282 or(scc,R1,INT_ALL_Rx|TxINT_ENAB|EXT_INT_ENAB);
1283
1284 scc->status = InReg(scc->ctrl,R0);
1285
1286 or(scc,R9,MIE);
1287
1288 scc_init_timer(scc);
1289
1290 restore_flags(flags);
1291 }
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304 static void
1305 scc_key_trx(struct scc_channel *scc, char tx)
1306 {
1307 unsigned int time_const;
1308
1309 if (scc->modem.speed < baud_table[1])
1310 scc->modem.speed = 1200;
1311
1312 if (scc->brand & PRIMUS)
1313 Outb(scc->ctrl + 4, scc->option | (tx? 0x80 : 0));
1314
1315 time_const = (unsigned) (scc->clock / (scc->modem.speed * (tx? 2:64))) - 2;
1316
1317 if (scc->modem.clocksrc == CLK_DPLL)
1318 {
1319 if (tx)
1320 {
1321 cl(scc,R3,RxENABLE|ENT_HM);
1322
1323 set_brg(scc, time_const);
1324
1325
1326 wr(scc, R11, RCDPLL|TCBR|TRxCOI|TRxCBR);
1327
1328 or(scc,R5,RTS|TxENAB);
1329 } else {
1330 cl(scc,R5,RTS|TxENAB);
1331
1332 set_brg(scc, time_const);
1333
1334
1335 wr(scc, R11, RCDPLL|TCDPLL|TRxCOI|TRxCDP);
1336
1337 or(scc,R3,RxENABLE|ENT_HM);
1338 }
1339 } else {
1340 if (tx)
1341 or(scc,R5,RTS|TxENAB);
1342 else
1343 cl(scc,R5,RTS|TxENAB);
1344 }
1345 }
1346
1347
1348
1349
1350 static unsigned char Rand = 17;
1351
1352 static inline int is_grouped(register struct scc_channel *scc)
1353 {
1354 int k;
1355 struct scc_channel *scc2;
1356 unsigned char grp1, grp2;
1357
1358 grp1 = scc->kiss.group;
1359
1360 for (k = 0; k < (Nchips * 2); k++)
1361 {
1362 scc2 = &SCC_Info[k];
1363 grp2 = scc2->kiss.group;
1364
1365 if (scc2 == scc || !(scc2->tty && grp2))
1366 return 0;
1367
1368 if ((grp1 & 0x3f) == (grp2 & 0x3f))
1369 {
1370 if ( (grp1 & TXGROUP) && (scc2->wreg[R5] & RTS) )
1371 return 1;
1372
1373 if ( (grp1 & RXGROUP) && (scc2->status & DCD) )
1374 return 1;
1375 }
1376 }
1377 return 0;
1378 }
1379
1380
1381 static inline void dw_slot_timeout(register struct scc_channel *scc)
1382 {
1383 scc->t_dwait = TIMER_STOPPED;
1384 scc->t_slot = TIMER_STOPPED;
1385
1386 if (!scc->kiss.fulldup)
1387 {
1388 Rand = Rand * 17 + 31;
1389
1390 if ( (scc->kiss.softdcd? !(scc->status & SYNC_HUNT):(scc->status & DCD)) || (scc->kiss.persist) < Rand || (scc->kiss.group && is_grouped(scc)) )
1391 {
1392 if (scc->t_mbusy == TIMER_STOPPED)
1393 scc->t_mbusy = TPS * scc->kiss.maxdefer;
1394
1395 scc->t_slot = scc->kiss.slottime;
1396 return ;
1397
1398 }
1399 }
1400
1401 if ( !(scc->wreg[R5] & RTS) )
1402 {
1403 scc->t_txdel = scc->kiss.txdelay;
1404 scc_key_trx(scc, TX_ON);
1405 } else {
1406 scc->t_txdel = 0;
1407 }
1408 }
1409
1410
1411
1412
1413 static inline void txdel_timeout(register struct scc_channel *scc)
1414 {
1415 scc->t_txdel = TIMER_STOPPED;
1416
1417 scc->t_maxk = TPS * scc->kiss.maxkeyup;
1418
1419 if (scc->tx_bp == NULLBUF)
1420 scc_txint(scc);
1421 }
1422
1423
1424
1425 static inline void tail_timeout(register struct scc_channel *scc)
1426 {
1427 scc->t_tail = TIMER_STOPPED;
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437 if (scc->kiss.fulldup < 2)
1438 {
1439 if (scc->tx_bp)
1440 {
1441 scc->stat.tx_state = TXS_BUSY;
1442 scc->t_dwait = TPS * scc->kiss.mintime;
1443 }
1444
1445 scc->stat.tx_state = TXS_IDLE;
1446 scc->t_maxk = TIMER_STOPPED;
1447 scc_key_trx(scc, TX_OFF);
1448 return;
1449 }
1450
1451 if (scc->tx_bp)
1452 {
1453 scc->stat.tx_state = TXS_BUSY;
1454 scc->t_txdel = TPS * scc->kiss.waittime;
1455 }
1456 else
1457
1458 scc->t_idle = TPS * scc->kiss.idletime;
1459 }
1460
1461
1462 static inline void busy_timeout(register struct scc_channel *scc)
1463 {
1464 #ifdef THROW_AWAY_AFTER_BUSY_TIMEOUT
1465 register struct mbuf *bp;
1466
1467 while (bp = scc_dequeue_buffer(&scc->tx_queue))
1468 scc_enqueue_buffer(&scc->tx_buffer_pool, bp);
1469
1470 scc->tx_queue = NULLBUF;
1471 scc->stat.tx_state = TXS_IDLE;
1472
1473 #else
1474 scc->t_txdel = scc->kiss.txdelay;
1475 #endif
1476 scc->t_mbusy = TIMER_STOPPED;
1477
1478 }
1479
1480
1481 static inline void maxk_idle_timeout(register struct scc_channel *scc)
1482 {
1483 scc->t_maxk = TIMER_STOPPED;
1484 scc->t_idle = TIMER_STOPPED;
1485
1486 scc->stat.tx_state = TXS_BUSY;
1487 scc->t_tail = scc->kiss.tailtime;
1488 }
1489
1490 static void
1491 scc_tx_timer(unsigned long channel)
1492 {
1493 register struct scc_channel *scc;
1494 unsigned long flags;
1495
1496
1497 scc = (struct scc_channel *) channel;
1498
1499 if (scc->tty && scc->init)
1500 {
1501 save_flags(flags); cli();
1502
1503
1504
1505 if (Expired(t_dwait)) dw_slot_timeout(scc) ; else
1506 if (Expired(t_slot)) dw_slot_timeout(scc) ; else
1507 if (Expired(t_txdel)) txdel_timeout(scc) ; else
1508 if (Expired(t_tail)) tail_timeout(scc) ;
1509
1510
1511
1512 if (Expired(t_mbusy)) busy_timeout(scc);
1513 if (Expired(t_maxk)) maxk_idle_timeout(scc);
1514 if (Expired(t_idle)) maxk_idle_timeout(scc);
1515
1516 restore_flags(flags);
1517 }
1518
1519 scc->tx_t.expires = jiffies + HZ/TPS;
1520 add_timer(&scc->tx_t);
1521 }
1522
1523
1524 static void
1525 scc_rx_timer(unsigned long channel)
1526 {
1527 register struct scc_channel *scc;
1528
1529 scc = (struct scc_channel *) channel;
1530
1531 if (scc->rx_queue && scc->throttled)
1532 {
1533 scc->rx_t.expires = jiffies + HZ/TPS;
1534 add_timer(&scc->rx_t);
1535 return;
1536 }
1537
1538 kiss_encode(scc);
1539
1540 if (scc->rx_queue && !scc->throttled)
1541 {
1542
1543 printk("z8530drv: warning: %s should be throttled\n",
1544 kdevname(scc->tty->device));
1545
1546 scc->rx_t.expires = jiffies + HZ/TPS;
1547 add_timer(&scc->rx_t);
1548 }
1549 }
1550
1551 static void
1552 scc_init_timer(struct scc_channel *scc)
1553 {
1554 unsigned long flags;
1555
1556 save_flags(flags); cli();
1557
1558 Stop_Timer(t_dwait);
1559 Stop_Timer(t_slot);
1560 Stop_Timer(t_txdel);
1561 Stop_Timer(t_tail);
1562 Stop_Timer(t_mbusy);
1563 Stop_Timer(t_maxk);
1564 Stop_Timer(t_idle);
1565
1566 scc->stat.tx_state = TXS_IDLE;
1567
1568 if (scc->tx_t.next)
1569 del_timer(&scc->tx_t);
1570
1571 scc->tx_t.data = (unsigned long) scc;
1572 scc->tx_t.function = scc_tx_timer;
1573 scc->tx_t.expires = jiffies + HZ/TPS;
1574 add_timer(&scc->tx_t);
1575
1576 scc->rx_t.data = (unsigned long) scc;
1577 scc->rx_t.function = scc_rx_timer;
1578
1579 restore_flags(flags);
1580 }
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592 static void
1593 kiss_set_param(struct scc_channel *scc,char cmd, unsigned int val)
1594 {
1595
1596 #define VAL val=val*TPS/100
1597 #define SVAL val? val:TIMER_STOPPED
1598
1599 switch(cmd){
1600 case PARAM_TXDELAY:
1601 scc->kiss.txdelay = VAL; break;
1602 case PARAM_PERSIST:
1603 scc->kiss.persist = val; break;
1604 case PARAM_SLOTTIME:
1605 scc->kiss.slottime = VAL; break;
1606 case PARAM_TXTAIL:
1607 scc->kiss.tailtime = VAL; break;
1608 case PARAM_FULLDUP:
1609 scc->kiss.fulldup = val; break;
1610 case PARAM_WAIT:
1611 scc->kiss.waittime = VAL; break;
1612 case PARAM_MAXKEY:
1613 scc->kiss.maxkeyup = SVAL; break;
1614 case PARAM_MIN:
1615 scc->kiss.mintime = SVAL; break;
1616 case PARAM_IDLE:
1617 scc->kiss.idletime = val; break;
1618 case PARAM_MAXDEFER:
1619 scc->kiss.maxdefer = SVAL; break;
1620 case PARAM_GROUP:
1621 scc->kiss.group = val; break;
1622 case PARAM_TX:
1623 scc->kiss.tx_inhibit = val;
1624 case PARAM_SOFTDCD:
1625 scc->kiss.softdcd = val;
1626 }
1627 return;
1628
1629 #undef VAL
1630 #undef SVAL
1631 }
1632
1633
1634
1635
1636 static void kiss_interpret_frame(struct scc_channel * scc)
1637 {
1638 unsigned char kisscmd;
1639 unsigned long flags;
1640 struct mbuf *bp;
1641
1642 bp = scc->kiss_decode_bp;
1643 bp->rw_ptr = bp->data;
1644
1645 #ifdef DEBUG_BUFFERS
1646 if (bp == NULLBUF)
1647 {
1648 printk("kiss_interpret_frame(): weird --- nothing to do.\n");
1649 return;
1650 }
1651 #endif
1652
1653 if (bp->cnt < 2)
1654 {
1655 scc_enqueue_buffer(&scc->tx_buffer_pool, bp);
1656 scc->kiss_decode_bp = NULLBUF;
1657 return;
1658 }
1659
1660
1661
1662 if (scc->kiss.not_slip)
1663 {
1664 kisscmd = *bp->rw_ptr;
1665 bp->rw_ptr++;
1666 } else {
1667 kisscmd = 0;
1668 }
1669
1670 if (kisscmd & 0xa0)
1671 {
1672 if (bp->cnt > 3)
1673 bp->cnt -= 2;
1674 else
1675 {
1676 scc_enqueue_buffer(&scc->tx_buffer_pool, bp);
1677 scc->kiss_decode_bp = NULLBUF;
1678 return;
1679 }
1680 }
1681
1682
1683 kisscmd &= 0x1f;
1684
1685
1686 if (kisscmd)
1687 {
1688 kiss_set_param(scc, kisscmd, *bp->rw_ptr);
1689 scc_enqueue_buffer(&scc->tx_buffer_pool, bp);
1690 scc->kiss_decode_bp = NULLBUF;
1691 return;
1692 }
1693
1694 scc_enqueue_buffer(&scc->tx_queue, bp);
1695
1696 scc->stat.txframes++;
1697 scc->stat.tx_queued++;
1698 scc->kiss_decode_bp = NULLBUF;
1699
1700 save_flags(flags); cli();
1701
1702 if(scc->stat.tx_state == TXS_IDLE)
1703 {
1704 scc->stat.tx_state = TXS_BUSY;
1705 scc->t_dwait = (scc->kiss.fulldup? 0:scc->kiss.waittime);
1706 }
1707
1708 restore_flags(flags);
1709 }
1710
1711 static inline void kiss_store_byte(struct scc_channel *scc, unsigned char ch)
1712 {
1713 register struct mbuf *bp = scc->kiss_decode_bp;
1714
1715 if (bp != NULLBUF)
1716 {
1717 if (bp->cnt > scc->stat.bufsize)
1718 printk("kiss_decode(): frame too long\n");
1719 else
1720 {
1721 *bp->rw_ptr = ch;
1722 bp->rw_ptr++;
1723 bp->cnt++;
1724 }
1725 }
1726 }
1727
1728 static inline int kiss_decode(struct scc_channel *scc, unsigned char ch)
1729 {
1730 switch (scc->stat.tx_kiss_state)
1731 {
1732 case KISS_IDLE:
1733 if (ch == FEND)
1734 {
1735 scc->kiss_decode_bp = scc_get_buffer(scc, BT_TRANSMIT);
1736 if (scc->kiss_decode_bp == NULLBUF)
1737 return 1;
1738
1739 scc->stat.tx_kiss_state = KISS_DATA;
1740 } else scc->stat.txerrs++;
1741 break;
1742
1743 case KISS_DATA:
1744 if (ch == FESC)
1745 scc->stat.tx_kiss_state = KISS_ESCAPE;
1746 else if (ch == FEND)
1747 {
1748 kiss_interpret_frame(scc);
1749 scc->stat.tx_kiss_state = KISS_IDLE;
1750 }
1751 else kiss_store_byte(scc, ch);
1752 break;
1753
1754 case KISS_ESCAPE:
1755 if (ch == TFEND)
1756 {
1757 kiss_store_byte(scc, FEND);
1758 scc->stat.tx_kiss_state = KISS_DATA;
1759 }
1760 else if (ch == TFESC)
1761 {
1762 kiss_store_byte(scc, FESC);
1763 scc->stat.tx_kiss_state = KISS_DATA;
1764 }
1765 else
1766 {
1767 scc_enqueue_buffer(&scc->tx_buffer_pool, scc->kiss_decode_bp);
1768 scc->kiss_decode_bp = NULLBUF;
1769 scc->stat.txerrs++;
1770 scc->stat.tx_kiss_state = KISS_IDLE;
1771 }
1772 break;
1773 }
1774
1775 return 0;
1776
1777 }
1778
1779
1780
1781 static void
1782 kiss_encode(register struct scc_channel *scc)
1783 {
1784 struct mbuf *bp;
1785 struct tty_struct * tty = scc->tty;
1786 unsigned char ch;
1787
1788 bp = scc->kiss_encode_bp;
1789
1790
1791
1792 while(tty->flip.count < TTY_FLIPBUF_SIZE-4)
1793 {
1794 if (bp == NULLBUF)
1795 {
1796 bp = scc_dequeue_buffer(&scc->rx_queue);
1797 scc->kiss_encode_bp = bp;
1798
1799 if (bp == NULLBUF)
1800 {
1801 scc->stat.rx_kiss_state = KISS_IDLE;
1802 break;
1803 }
1804 }
1805
1806
1807 if (bp->cnt <= 0)
1808 {
1809 if (--scc->stat.rx_queued < 0)
1810 scc->stat.rx_queued = 0;
1811
1812 if (scc->stat.rx_kiss_state == KISS_RXFRAME)
1813 {
1814 tty_insert_flip_char(tty, FEND, 0);
1815 scc->stat.rx_kiss_state = KISS_IDLE;
1816 }
1817
1818 scc_enqueue_buffer(&scc->rx_buffer_pool, bp);
1819
1820 bp = scc->kiss_encode_bp = NULLBUF;
1821 continue;
1822 }
1823
1824
1825 if (scc->stat.rx_kiss_state == KISS_IDLE)
1826 {
1827 tty_insert_flip_char(tty, FEND, 0);
1828
1829 if (scc->kiss.not_slip)
1830 tty_insert_flip_char(tty, 0, 0);
1831
1832 scc->stat.rx_kiss_state = KISS_RXFRAME;
1833 }
1834
1835 switch(ch = *bp->rw_ptr)
1836 {
1837 case FEND:
1838 tty_insert_flip_char(tty, FESC, 0);
1839 tty_insert_flip_char(tty, TFEND, 0);
1840 break;
1841 case FESC:
1842 tty_insert_flip_char(tty, FESC, 0);
1843 tty_insert_flip_char(tty, TFESC, 0);
1844 break;
1845 default:
1846 tty_insert_flip_char(tty, ch, 0);
1847 }
1848
1849 bp->rw_ptr++;
1850 bp->cnt--;
1851 }
1852
1853 queue_task(&tty->flip.tqueue, &tq_timer);
1854 }
1855
1856
1857
1858
1859
1860
1861
1862 static void
1863 z8530_init(void)
1864 {
1865 struct scc_channel *scc;
1866 int chip, k;
1867 unsigned long flags;
1868 char *flag;
1869
1870
1871 printk("Init Z8530 driver: %u channels, IRQ", Nchips*2);
1872
1873 flag=" ";
1874 for (k = 0; k < 16; k++)
1875 if (Ivec[k].used)
1876 {
1877 printk("%s%d", flag, k);
1878 flag=",";
1879 }
1880 printk("\n");
1881
1882
1883
1884 for (chip = 0; chip < Nchips; chip++)
1885 {
1886 scc=&SCC_Info[2*chip];
1887 if (!scc->ctrl) continue;
1888
1889 save_flags(flags); cli();
1890
1891
1892
1893 if(scc->brand & EAGLE)
1894 Outb(scc->special,0x08);
1895
1896 if(scc->brand & (PC100 | PRIMUS))
1897 Outb(scc->special,scc->option);
1898
1899
1900
1901
1902
1903
1904 Outb(scc->ctrl, 0);
1905 OutReg(scc->ctrl,R9,FHWRES);
1906 udelay(100);
1907 wr(scc, R2, chip*16);
1908 wr(scc, R9, VIS);
1909
1910 restore_flags(flags);
1911 }
1912
1913
1914 Driver_Initialized = 1;
1915 }
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926 static inline int scc_paranoia_check(struct scc_channel *scc, kdev_t device,
1927 const char *routine)
1928 {
1929 #ifdef SCC_PARANOIA_CHECK
1930
1931 static const char *badmagic =
1932 "Warning: bad magic number for Z8530 SCC struct (%s) in %s\n";
1933 static const char *badinfo =
1934 "Warning: Z8530 not found for (%s) in %s\n";
1935
1936 if (!scc->init)
1937 {
1938 printk(badinfo, kdevname(device), routine);
1939 return 1;
1940 }
1941
1942 if (scc->magic != SCC_MAGIC)
1943 {
1944 printk(badmagic, kdevname(device), routine);
1945 return 1;
1946 }
1947 #endif
1948
1949 return 0;
1950 }
1951
1952
1953
1954
1955 int scc_open(struct tty_struct *tty, struct file * filp)
1956 {
1957 struct scc_channel *scc;
1958 int chan;
1959
1960 chan = MINOR(tty->device) - tty->driver.minor_start;
1961
1962 if (Driver_Initialized)
1963 {
1964 if ( (chan < 0) || (chan >= (Nchips * 2)) )
1965 return -ENODEV;
1966 } else {
1967 tty->driver_data = &SCC_Info[0];
1968 MOD_INC_USE_COUNT;
1969 return 0;
1970 }
1971
1972 scc = &SCC_Info[chan];
1973
1974 tty->driver_data = scc;
1975 tty->termios->c_cflag &= ~CBAUD;
1976
1977 if (scc->magic != SCC_MAGIC)
1978 {
1979 printk("ERROR: scc_open(): bad magic number for device (%s)",
1980 kdevname(tty->device));
1981 return -ENODEV;
1982 }
1983
1984 MOD_INC_USE_COUNT;
1985
1986 if(scc->tty != NULL)
1987 {
1988 scc->tty_opened++;
1989 return 0;
1990 }
1991
1992 scc->tty = tty;
1993 alloc_buffer_pool(scc);
1994
1995 if(!scc->init) return 0;
1996
1997 scc->throttled = 0;
1998
1999 scc->stat.tx_kiss_state = KISS_IDLE;
2000 scc->stat.rx_kiss_state = KISS_IDLE;
2001
2002 init_channel(scc);
2003 return 0;
2004 }
2005
2006
2007
2008
2009 static void
2010 scc_close(struct tty_struct *tty, struct file * filp)
2011 {
2012 struct scc_channel *scc = tty->driver_data;
2013 unsigned long flags;
2014
2015 if (!scc || (scc->magic != SCC_MAGIC))
2016 return;
2017
2018 MOD_DEC_USE_COUNT;
2019
2020 if(scc->tty_opened)
2021 {
2022 scc->tty_opened--;
2023 return;
2024 }
2025
2026 tty->driver_data = NULLBUF;
2027
2028 if (!Driver_Initialized)
2029 return;
2030
2031 save_flags(flags); cli();
2032
2033 Outb(scc->ctrl,0);
2034 wr(scc,R1,0);
2035 wr(scc,R3,0);
2036
2037 scc->tty = NULL;
2038
2039 del_timer(&scc->tx_t);
2040 del_timer(&scc->rx_t);
2041
2042 free_buffer_pool(scc);
2043
2044 restore_flags(flags);
2045
2046 scc->throttled = 0;
2047 tty->stopped = 0;
2048 }
2049
2050
2051
2052
2053
2054
2055 static void
2056 scc_change_speed(struct scc_channel * scc)
2057 {
2058 long speed;
2059
2060 if (scc->tty == NULL)
2061 return;
2062
2063
2064 speed = baud_table[scc->tty->termios->c_cflag & CBAUD];
2065
2066 if (speed > 0) scc->modem.speed = speed;
2067
2068 if (scc->stat.tx_state == 0)
2069 set_speed(scc);
2070 }
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091 static int
2092 scc_ioctl(struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
2093 {
2094 struct scc_channel * scc = tty->driver_data;
2095 unsigned long flags, r;
2096 unsigned int result;
2097 unsigned int value;
2098 struct ioctl_command kiss_cmd;
2099 struct scc_mem_config memcfg;
2100 struct scc_hw_config hwcfg;
2101 int error, chan;
2102
2103 if (scc->magic != SCC_MAGIC)
2104 {
2105 printk("ERROR: scc_ioctl(): bad magic number for device %s",
2106 kdevname(tty->device));
2107
2108 return -ENODEV;
2109 }
2110
2111 r = NO_SUCH_PARAM;
2112
2113 if (!Driver_Initialized)
2114 {
2115 if (cmd == TIOCSCCCFG)
2116 {
2117 int found = 1;
2118
2119 if (!suser()) return -EPERM;
2120 if (!arg) return -EFAULT;
2121
2122 if (Nchips >= MAXSCC)
2123 return -EINVAL;
2124
2125 memcpy_fromfs(&hwcfg, (void *) arg, sizeof(hwcfg));
2126
2127 if (hwcfg.irq == 2) hwcfg.irq = 9;
2128
2129 if (!Ivec[hwcfg.irq].used && hwcfg.irq)
2130 {
2131 if (request_irq(hwcfg.irq, scc_isr, SA_INTERRUPT, "AX.25 SCC"))
2132 printk("z8530drv: Warning --- could not get IRQ %d\n", hwcfg.irq);
2133 else
2134 Ivec[hwcfg.irq].used = 1;
2135 }
2136
2137 if (hwcfg.vector_latch)
2138 Vector_Latch = hwcfg.vector_latch;
2139
2140 if (hwcfg.clock == 0)
2141 hwcfg.clock = DEFAULT_CLOCK;
2142
2143 #ifndef DONT_CHECK
2144 save_flags(flags); cli();
2145
2146 check_region(scc->ctrl, 1);
2147 Outb(hwcfg.ctrl_a, 0);
2148 udelay(5);
2149 OutReg(hwcfg.ctrl_a,R13,0x55);
2150 udelay(5);
2151
2152 if (InReg(hwcfg.ctrl_a,R13) != 0x55 )
2153 found = 0;
2154
2155 restore_flags(flags);
2156 #endif
2157
2158 if (found)
2159 {
2160 SCC_Info[2*Nchips ].ctrl = hwcfg.ctrl_a;
2161 SCC_Info[2*Nchips ].data = hwcfg.data_a;
2162 SCC_Info[2*Nchips+1].ctrl = hwcfg.ctrl_b;
2163 SCC_Info[2*Nchips+1].data = hwcfg.data_b;
2164
2165 SCC_ctrl[2*Nchips ] = hwcfg.ctrl_a;
2166 SCC_ctrl[2*Nchips+1] = hwcfg.ctrl_b;
2167 }
2168
2169 for (chan = 0; chan < 2; chan++)
2170 {
2171 SCC_Info[2*Nchips+chan].special = hwcfg.special;
2172 SCC_Info[2*Nchips+chan].clock = hwcfg.clock;
2173 SCC_Info[2*Nchips+chan].brand = hwcfg.brand;
2174 SCC_Info[2*Nchips+chan].option = hwcfg.option;
2175 SCC_Info[2*Nchips+chan].enhanced = hwcfg.escc;
2176
2177 #ifdef DONT_CHECK
2178 printk("%s%i: data port = 0x%3.3x control port = 0x%3.3x\n",
2179 scc_driver.name, 2*Nchips+chan,
2180 SCC_Info[2*Nchips+chan].data,
2181 SCC_Info[2*Nchips+chan].ctrl);
2182
2183 #else
2184 printk("%s%i: data port = 0x%3.3x control port = 0x%3.3x -- %s\n",
2185 scc_driver.name, 2*Nchips+chan,
2186 chan? hwcfg.data_b : hwcfg.data_a,
2187 chan? hwcfg.ctrl_b : hwcfg.ctrl_a,
2188 found? "found" : "missing");
2189 #endif
2190
2191 if (found)
2192 {
2193 request_region(SCC_Info[2*Nchips+chan].ctrl, 1, "scc ctrl");
2194 request_region(SCC_Info[2*Nchips+chan].data, 1, "scc data");
2195 }
2196 }
2197
2198 if (found) Nchips++;
2199
2200 return 0;
2201 }
2202
2203 if (cmd == TIOCSCCINI)
2204 {
2205 if (!suser())
2206 return -EPERM;
2207
2208 if (Nchips == 0)
2209 return -EINVAL;
2210
2211 z8530_init();
2212
2213 scc->tty=tty;
2214 alloc_buffer_pool(scc);
2215 return 0;
2216 }
2217
2218 return -EINVAL;
2219 }
2220
2221 if (!scc->init)
2222 {
2223 if (cmd == TIOCCHANINI)
2224 {
2225 if (!arg)
2226 return -EFAULT;
2227
2228 if (!suser())
2229 return -EPERM;
2230
2231 memcpy_fromfs(&scc->modem, (void *) arg, sizeof(struct scc_modem));
2232
2233
2234
2235 if (scc->modem.speed < 4800)
2236 {
2237 scc->kiss.txdelay = 36*TPS/100;
2238 scc->kiss.persist = 42;
2239 scc->kiss.slottime = 16*TPS/100;
2240 scc->kiss.tailtime = 4;
2241 scc->kiss.fulldup = 0;
2242 scc->kiss.waittime = 50*TPS/100;
2243 scc->kiss.maxkeyup = 10;
2244 scc->kiss.mintime = 3;
2245 scc->kiss.idletime = 30;
2246 scc->kiss.maxdefer = 120;
2247 scc->kiss.not_slip = 1;
2248 scc->kiss.softdcd = 0;
2249 } else {
2250 scc->kiss.txdelay = 10*TPS/100;
2251 scc->kiss.persist = 64;
2252 scc->kiss.slottime = 8*TPS/100;
2253 scc->kiss.tailtime = 1;
2254 scc->kiss.fulldup = 0;
2255 scc->kiss.waittime = 50*TPS/100;
2256 scc->kiss.maxkeyup = 7;
2257 scc->kiss.mintime = 3;
2258 scc->kiss.idletime = 30;
2259 scc->kiss.maxdefer = 120;
2260 scc->kiss.not_slip = 1;
2261 scc->kiss.softdcd = 0;
2262 }
2263
2264 scc->init = 1;
2265
2266 return 0;
2267 }
2268
2269 return -EINVAL;
2270 }
2271
2272 switch(cmd){
2273 case TCSBRK:
2274 return 0;
2275 case TIOCMGET:
2276 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(unsigned int *));
2277 if (error)
2278 return error;
2279
2280 save_flags(flags); cli();
2281
2282 result = ((scc->wreg[R5] & RTS) ? TIOCM_RTS : 0)
2283 | ((scc->wreg[R5] & DTR) ? TIOCM_DTR : 0)
2284 | ((InReg(scc->ctrl,R0) & DCD) ? TIOCM_CAR : 0)
2285 | ((InReg(scc->ctrl,R0) & CTS) ? TIOCM_CTS : 0);
2286
2287 restore_flags(flags);
2288
2289 put_user_long(result,(unsigned int *) arg);
2290 return 0;
2291 case TIOCMBIS:
2292 case TIOCMBIC:
2293 case TIOCMSET:
2294 switch (cmd) {
2295 case TIOCMBIS:
2296 scc->wreg[R5] |= DTR;
2297 scc->wreg[R5] |= RTS;
2298 break;
2299 case TIOCMBIC:
2300 scc->wreg[R5] &= ~DTR;
2301 scc->wreg[R5] &= ~RTS;
2302 break;
2303 case TIOCMSET:
2304 value = get_user_long((unsigned int *) arg);
2305
2306 if(value & TIOCM_DTR)
2307 scc->wreg[R5] |= DTR;
2308 else
2309 scc->wreg[R5] &= ~DTR;
2310 if(value & TIOCM_RTS)
2311 scc->wreg[R5] |= RTS;
2312 else
2313 scc->wreg[R5] &= ~RTS;
2314 break;
2315 }
2316
2317 save_flags(flags); cli();
2318
2319 if(scc->stat.tx_state == TXS_IDLE && !Running(t_idle))
2320 maxk_idle_timeout(scc);
2321
2322 restore_flags(flags);
2323
2324 return 0;
2325
2326 case TCGETS:
2327 error = verify_area(VERIFY_WRITE, (void *) arg, sizeof(struct termios));
2328 if (error)
2329 return error;
2330 if (!arg)
2331 return -EFAULT;
2332
2333 memcpy_tofs((void *) arg, scc->tty->termios, sizeof(struct termios));
2334 return 0;
2335
2336 case TCSETS:
2337 case TCSETSF:
2338 case TCSETSW:
2339 if (!arg)
2340 return -EFAULT;
2341
2342 memcpy_fromfs(scc->tty->termios, (void *) arg, sizeof(struct termios));
2343 scc_change_speed(scc);
2344 return 0;
2345
2346 case TIOCCHANMEM:
2347 if (!arg)
2348 return -EFAULT;
2349
2350 memcpy_fromfs(&memcfg, (void *) arg, sizeof(struct scc_mem_config));
2351
2352 save_flags(flags); cli();
2353
2354 free_buffer_pool(scc);
2355 scc->stat.rxbuffers = memcfg.rxbuffers;
2356 scc->stat.txbuffers = memcfg.txbuffers;
2357 scc->stat.bufsize = memcfg.bufsize;
2358 alloc_buffer_pool(scc);
2359
2360 restore_flags(flags);
2361 return 0;
2362
2363
2364 case TIOCSCCSTAT:
2365 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(struct scc_stat));
2366 if (error)
2367 return error;
2368
2369 if (!arg)
2370 return -EFAULT;
2371
2372 memcpy_tofs((void *) arg, &scc->stat, sizeof(struct scc_stat));
2373 return 0;
2374
2375 #define TICKS (100/TPS)
2376 #define CAST(x) (unsigned long)(x)
2377 #define Val kiss_cmd.param
2378 #define VAL kiss_cmd.param*TPS/100
2379 #define SVAL kiss_cmd.param? kiss_cmd.param:TIMER_STOPPED
2380
2381 case TIOCGKISS:
2382 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(struct ioctl_command));
2383 if (error)
2384 return error;
2385
2386 if (!arg)
2387 return -EFAULT;
2388
2389 memcpy_fromfs(&kiss_cmd, (void *) arg, sizeof(struct ioctl_command));
2390
2391 switch (kiss_cmd.command)
2392 {
2393 case PARAM_TXDELAY: r = CAST(scc->kiss.txdelay*TICKS); break;
2394 case PARAM_PERSIST: r = CAST(scc->kiss.persist); break;
2395 case PARAM_SLOTTIME: r = CAST(scc->kiss.slottime*TICKS); break;
2396 case PARAM_TXTAIL: r = CAST(scc->kiss.tailtime*TICKS); break;
2397 case PARAM_FULLDUP: r = CAST(scc->kiss.fulldup); break;
2398 case PARAM_SOFTDCD: r = CAST(scc->kiss.softdcd); break;
2399 case PARAM_DTR: r = CAST((scc->wreg[R5] & DTR)? 1:0); break;
2400 case PARAM_RTS: r = CAST((scc->wreg[R5] & RTS)? 1:0); break;
2401 case PARAM_SPEED: r = CAST(scc->modem.speed); break;
2402 case PARAM_GROUP: r = CAST(scc->kiss.group); break;
2403 case PARAM_IDLE: r = CAST(scc->kiss.idletime); break;
2404 case PARAM_MIN: r = CAST(scc->kiss.mintime); break;
2405 case PARAM_MAXKEY: r = CAST(scc->kiss.maxkeyup); break;
2406 case PARAM_WAIT: r = CAST(scc->kiss.waittime); break;
2407 case PARAM_MAXDEFER: r = CAST(scc->kiss.maxdefer); break;
2408 case PARAM_TX: r = CAST(scc->kiss.tx_inhibit); break;
2409 case PARAM_SLIP: r = CAST(!scc->kiss.not_slip); break;
2410 default: r = NO_SUCH_PARAM;
2411 }
2412
2413 kiss_cmd.param = r;
2414
2415 memcpy_tofs((void *) arg, &kiss_cmd, sizeof(struct ioctl_command));
2416 return 0;
2417 break;
2418
2419 case TIOCSKISS:
2420 if (!arg)
2421 return -EFAULT;
2422
2423 memcpy_fromfs(&kiss_cmd, (void *) arg, sizeof(struct ioctl_command));
2424
2425 switch (kiss_cmd.command)
2426 {
2427 case PARAM_TXDELAY: scc->kiss.txdelay=VAL; break;
2428 case PARAM_PERSIST: scc->kiss.persist=Val; break;
2429 case PARAM_SLOTTIME: scc->kiss.slottime=VAL; break;
2430 case PARAM_TXTAIL: scc->kiss.tailtime=VAL; break;
2431 case PARAM_FULLDUP: scc->kiss.fulldup=Val; break;
2432 case PARAM_SOFTDCD: scc->kiss.softdcd=Val; break;
2433 case PARAM_DTR: break;
2434 case PARAM_RTS: break;
2435 case PARAM_SPEED: scc->modem.speed=Val; break;
2436 case PARAM_GROUP: scc->kiss.group=Val; break;
2437 case PARAM_IDLE: scc->kiss.idletime=Val; break;
2438 case PARAM_MIN: scc->kiss.mintime=SVAL; break;
2439 case PARAM_MAXKEY: scc->kiss.maxkeyup=SVAL; break;
2440 case PARAM_WAIT: scc->kiss.waittime=Val; break;
2441 case PARAM_MAXDEFER: scc->kiss.maxdefer=SVAL; break;
2442 case PARAM_TX: scc->kiss.tx_inhibit=Val; break;
2443 case PARAM_SLIP: scc->kiss.not_slip=!Val; break;
2444 default: return -ENOIOCTLCMD;
2445 }
2446
2447 return 0;
2448 break;
2449 #undef TICKS
2450 #undef CAST
2451 #undef VAL
2452 #undef SVAL
2453 #undef Val
2454
2455 default:
2456 return -ENOIOCTLCMD;
2457 }
2458 }
2459
2460
2461
2462
2463
2464 int scc_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
2465 {
2466 struct scc_channel * scc = tty->driver_data;
2467 unsigned char *p;
2468 unsigned long flags;
2469 int cnt, cnt2;
2470
2471 if (!tty) return count;
2472
2473 if (scc_paranoia_check(scc, tty->device, "scc_write"))
2474 return 0;
2475
2476 if (scc->kiss.tx_inhibit) return count;
2477
2478 save_flags(flags); cli();
2479
2480 cnt2 = count;
2481
2482 while (cnt2)
2483 {
2484 cnt = cnt2 > BUFSIZE? BUFSIZE:cnt2;
2485 cnt2 -= cnt;
2486
2487 if (from_user)
2488 {
2489 down(&scc_sem);
2490 memcpy_fromfs(scc_wbuf, buf, cnt);
2491 up(&scc_sem);
2492 }
2493 else
2494 memcpy(scc_wbuf, buf, cnt);
2495
2496
2497
2498
2499 if (cnt2 == 0)
2500 {
2501 wake_up_interruptible(&tty->write_wait);
2502
2503 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2504 tty->ldisc.write_wakeup)
2505 (tty->ldisc.write_wakeup)(tty);
2506 } else
2507 buf += cnt;
2508
2509 p=scc_wbuf;
2510
2511 while(cnt--)
2512 if (kiss_decode(scc, *p++))
2513 {
2514 scc->stat.nospace++;
2515 restore_flags(flags);
2516 return 0;
2517 }
2518 }
2519
2520 restore_flags(flags);
2521
2522 return count;
2523 }
2524
2525
2526
2527
2528 static void scc_put_char(struct tty_struct * tty, unsigned char ch)
2529 {
2530 struct scc_channel *scc = tty->driver_data;
2531 unsigned char ch2;
2532
2533 if (scc_paranoia_check(scc, tty->device, "scc_put_char"))
2534 return;
2535
2536 ch2 = ch;
2537 scc_write(tty, 0, &ch2, 1);
2538 }
2539
2540 static void scc_flush_chars(struct tty_struct * tty)
2541 {
2542 struct scc_channel *scc = tty->driver_data;
2543
2544 scc_paranoia_check(scc, tty->device, "scc_flush_chars");
2545
2546 return;
2547 }
2548
2549
2550 static int scc_write_room(struct tty_struct *tty)
2551 {
2552 struct scc_channel *scc = tty->driver_data;
2553
2554 if (scc_paranoia_check(scc, tty->device, "scc_write_room"))
2555 return 0;
2556
2557 return BUFSIZE;
2558 }
2559
2560 static int scc_chars_in_buffer(struct tty_struct *tty)
2561 {
2562 struct scc_channel *scc = tty->driver_data;
2563
2564 if (scc && scc->kiss_decode_bp)
2565 return scc->kiss_decode_bp->cnt;
2566 else
2567 return 0;
2568 }
2569
2570 static void scc_flush_buffer(struct tty_struct *tty)
2571 {
2572 struct scc_channel *scc = tty->driver_data;
2573
2574 if (scc_paranoia_check(scc, tty->device, "scc_flush_buffer"))
2575 return;
2576 wake_up_interruptible(&tty->write_wait);
2577 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2578 tty->ldisc.write_wakeup)
2579 (tty->ldisc.write_wakeup)(tty);
2580 }
2581
2582 static void scc_throttle(struct tty_struct *tty)
2583 {
2584 struct scc_channel *scc = tty->driver_data;
2585
2586 if (scc_paranoia_check(scc, tty->device, "scc_throttle"))
2587 return;
2588
2589 #ifdef DEBUG
2590 printk("scc: scc_throttle() called for device %d\n", MINOR(tty->device));
2591 #endif
2592 scc->throttled = 1;
2593
2594 del_timer(&(scc->rx_t));
2595 scc->rx_t.expires = jiffies + HZ/TPS;
2596 add_timer(&scc->rx_t);
2597 }
2598
2599 static void scc_unthrottle(struct tty_struct *tty)
2600 {
2601 struct scc_channel *scc = tty->driver_data;
2602
2603 if (scc_paranoia_check(scc, tty->device, "scc_unthrottle"))
2604 return;
2605
2606 #ifdef DEBUG
2607 printk("scc: scc_unthrottle() called for device %d\n", MINOR(tty->device));
2608 #endif
2609 scc->throttled = 0;
2610 del_timer(&(scc->rx_t));
2611 scc_tx_timer(scc->rx_t.data);
2612 }
2613
2614
2615
2616 static void scc_start(struct tty_struct *tty)
2617 {
2618 struct scc_channel *scc = tty->driver_data;
2619
2620 if (scc_paranoia_check(scc, tty->device, "scc_start"))
2621 return;
2622
2623 scc_unthrottle(tty);
2624 }
2625
2626 static void scc_stop(struct tty_struct *tty)
2627 {
2628 struct scc_channel *scc = tty->driver_data;
2629
2630 if (scc_paranoia_check(scc, tty->device, "scc_stop"))
2631 return;
2632
2633 scc_throttle(tty);
2634 }
2635
2636 static void
2637 scc_set_termios(struct tty_struct * tty, struct termios * old_termios)
2638 {
2639 struct scc_channel *scc = tty->driver_data;
2640
2641 if (scc_paranoia_check(scc, tty->device, "scc_set_termios"))
2642 return;
2643
2644 if (old_termios && (tty->termios->c_cflag == old_termios->c_cflag))
2645 return;
2646
2647 scc_change_speed(scc);
2648 }
2649
2650 static void
2651 scc_set_ldisc(struct tty_struct * tty)
2652 {
2653 struct scc_channel *scc = tty->driver_data;
2654
2655 if (scc_paranoia_check(scc, tty->device, "scc_set_ldisc"))
2656 return;
2657
2658 scc_change_speed(scc);
2659 }
2660
2661
2662
2663
2664
2665
2666 int scc_init (void)
2667 {
2668 int chip, chan, k;
2669
2670 memset(&scc_std_termios, 0, sizeof(struct termios));
2671 memset(&scc_driver, 0, sizeof(struct tty_driver));
2672 scc_driver.magic = TTY_DRIVER_MAGIC;
2673 scc_driver.name = "scc";
2674 scc_driver.major = Z8530_MAJOR;
2675 scc_driver.minor_start = 0;
2676 scc_driver.num = MAXSCC*2;
2677 scc_driver.type = TTY_DRIVER_TYPE_SERIAL;
2678 scc_driver.subtype = 1;
2679 scc_driver.init_termios = scc_std_termios;
2680 scc_driver.init_termios.c_cflag = B9600 | CREAD | CS8 | HUPCL | CLOCAL;
2681 scc_driver.init_termios.c_iflag = IGNBRK | IGNPAR;
2682 scc_driver.flags = TTY_DRIVER_REAL_RAW;
2683 scc_driver.refcount = &scc_refcount;
2684 scc_driver.table = scc_table;
2685 scc_driver.termios = (struct termios **) scc_termios;
2686 scc_driver.termios_locked = (struct termios **) scc_termios_locked;
2687 scc_driver.open = scc_open;
2688 scc_driver.close = scc_close;
2689 scc_driver.write = scc_write;
2690 scc_driver.start = scc_start;
2691 scc_driver.stop = scc_stop;
2692
2693 scc_driver.put_char = scc_put_char;
2694 scc_driver.flush_chars = scc_flush_chars;
2695 scc_driver.write_room = scc_write_room;
2696 scc_driver.chars_in_buffer = scc_chars_in_buffer;
2697 scc_driver.flush_buffer = scc_flush_buffer;
2698
2699 scc_driver.throttle = scc_throttle;
2700 scc_driver.unthrottle = scc_unthrottle;
2701
2702 scc_driver.ioctl = scc_ioctl;
2703 scc_driver.set_termios = scc_set_termios;
2704 scc_driver.set_ldisc = scc_set_ldisc;
2705
2706 printk(BANNER);
2707
2708 if (tty_register_driver(&scc_driver))
2709 {
2710 printk("Failed to register Z8530 SCC driver\n");
2711 return -EIO;
2712 }
2713
2714
2715
2716 for (chip = 0; chip < MAXSCC; chip++)
2717 {
2718 memset((char *) &SCC_Info[2*chip ], 0, sizeof(struct scc_channel));
2719 memset((char *) &SCC_Info[2*chip+1], 0, sizeof(struct scc_channel));
2720
2721 for (chan = 0; chan < 2; chan++)
2722 {
2723 SCC_Info[2*chip+chan].magic = SCC_MAGIC;
2724 SCC_Info[2*chip+chan].stat.rxbuffers = RXBUFFERS;
2725 SCC_Info[2*chip+chan].stat.txbuffers = TXBUFFERS;
2726 SCC_Info[2*chip+chan].stat.bufsize = BUFSIZE;
2727 }
2728 }
2729
2730 for (k = 0; k < 16; k++) Ivec[k].used = 0;
2731
2732 return 0;
2733 }
2734
2735
2736
2737
2738
2739
2740 #ifdef MODULE
2741 int init_module(void)
2742 {
2743 int result = 0;
2744
2745 result = scc_init();
2746
2747 if (result == 0)
2748 printk("Copyright 1993,1995 Joerg Reuter DL1BKE (jreuter@lykos.tng.oche.de)\n");
2749
2750 return result;
2751 }
2752
2753 void cleanup_module(void)
2754 {
2755 long flags;
2756 io_port ctrl;
2757 int k, errno;
2758 struct scc_channel *scc;
2759
2760 save_flags(flags); cli();
2761 if ( (errno = tty_unregister_driver(&scc_driver)) )
2762 {
2763 printk("Failed to unregister Z8530 SCC driver (%d)", -errno);
2764 restore_flags(flags);
2765 return;
2766 }
2767
2768 for (k = 0; k < Nchips; k++)
2769 if ( (ctrl = SCC_ctrl[k*2]) )
2770 {
2771 Outb(ctrl, 0);
2772 OutReg(ctrl,R9,FHWRES);
2773 udelay(50);
2774 }
2775
2776 for (k = 0; k < Nchips*2; k++)
2777 {
2778 scc = &SCC_Info[k];
2779 if (scc)
2780 {
2781 release_region(scc->ctrl, 1);
2782 release_region(scc->data, 1);
2783 }
2784 }
2785
2786 for (k=0; k < 16 ; k++)
2787 if (Ivec[k].used) free_irq(k);
2788
2789 restore_flags(flags);
2790 }
2791 #endif